자바에서 매우 간단한 파일 업로드 메커니즘이 있습니다. 방금 파일을 가져 와서 서버에 저장합니다. 셀렌으로이 간단한 코드를 테스트 중이며 셀레늄 테스트에서 시간 초과가 발생하면 tomcat_home/work/Catalina/localhost/uploadServlet/디렉토리 아래에 0 바이트 파일이 MultiPart * 파일로 생성됩니다. 장치에 디스크 공간이 남아 있지 않을 때까지 수천 개의 파일을 만듭니다. 이 문제의 원인은 무엇입니까? 이 문제를 어떻게 해결할 수 있습니까? 누구도 이것에 대한 아이디어가 있습니까?톰캣은 0 바이트 파일을 만듭니다.
내 환경은 : 우분투 - 8.04 서버, 아파치 톰캣 - 5.5.29, 태양 자바 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();
}
실제 코드를 게시하여 도움을주세요 : –
파일 작성이 끝나면 'OutputStream' 또는'Writer'에서'flush()'및/또는'close() '를 호출 하시겠습니까? – Jesper
나는 게시물을 편집하고 간단한 코드를 삽입했습니다. –