我在java中有一个非常简单的文件上传机制。我只是把这个文件保存在服务器上。我正在用selenium测试这个简单的代码,并且当在selenium测试中发生超时时,tomcat会在作为MultiPart *文件的tomcat_home/work/Catalina/localhost/uploadServlet /目录下创建0个字节的文件。它会创建数千个文件,直到设备上没有磁盘空间。什么可能导致这个问题?我该如何解决这个问题?有没有人对此有所了解?Tomcat创建0字节文件
我的环境是:Ubuntu的 - 8.04服务器,Apache Tomcat上 - 5.5.29,太阳的Java 1.6
感谢,
这里是代码片段,我使用
String strFileName = request.getParameter("FileName");
String strPath = request.getParameter("Path");
File fFile = (File) request.getAttribute("Content");
int index = strPath.length() - 1;
if (strPath.charAt(index) != '/') {
strPath += "/";
}
if (! new File(strPath).exists()) {
new File(strPath).mkdirs();
}
File file = new File(strPath + strFileName);
FileOutputStream fileOutputStream = new FileOutputStream(file);
FileInputStream fileInputStream = new FileInputStream(fFile);
byte[] bBuf = new byte[1024];
int iBufLen = 0;
int iReadLen = 1024;
int iTotelLen = 0;
/*read 1024 bytes at a time*/
while ((iBufLen = fileInputStream.read(bBuf)) != -1) {
fileOutputStream.write(bBuf);
fileOutputStream.flush();
iTotelLen += iBufLen;
if (fileInputStream.available() < iReadLen) {
iReadLen = fileInputStream.available();
break;
}
}
byte[] tempbBuf = new byte[iReadLen];
fileInputStream.read(tempbBuf, 0, iReadLen);
fileOutputStream.write(tempbBuf);
fileOutputStream.close();
fileInputStream.close();
if (fFile.exists()) {
fFile.delete();
}
请帮助我们通过发布您的实际代码来帮助您:-) – 2010-07-01 11:18:17
在完成写入文件后,您是否在'OutputStream'或'Writer'上调用'flush()'和/或close()'? – Jesper 2010-07-01 11:22:54
我编辑了帖子并插入了简单代码 – 2010-07-01 11:25:48