views:

65

answers:

1

Hi all,

I have a very simple file upload mechanism in java. I just take the file and save it on the server. I'm testing this simple code with selenium and when a timeout occurs in the selenium test tomcat creates 0 byte files under tomcat_home/work/Catalina/localhost/uploadServlet/ directory as MultiPart* files. It creates thousands of files, until there is no disk space left on device. What may cause this problem? How can I solve this? Is there anyone has an idea about this?

My environment is: Ubuntu - 8.04 server, apache tomcat - 5.5.29, sun java 1.6

Thanks,

Here is the code snippet that i use

    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();
    }
A: 

Is it possible that some sort of exception is occuring in the middle of this code? Best to close the streams in a finally block.

matt b
I've tried this one but the result doesn't change numerous 0 bytes.
small_ticket
do you know for sure that request.getAttribute("Content") contains anything with content? this part of the code is left out
matt b