Temporary files stays in linux after an attempt to delete

101 views Asked by At

I am writing a java servlet which downloads file from client and move it to some specific location. After move I delete the downloaded file. Sometimes linux creates .fuse_hidden______ named files. They stays there until I restart my server process. After download I do close all the opened streams. It usually happens on mounted USB flash drives.

Here is my code snippet

    try{
           ...
           inputStream = new RandomAccessFile(new File(sourcePath), "r");
           inputChannel = inputStream.getChannel();
           ....
        }
    finally{
           inputChannel.close(); 
           inputStream .close();
       }
    new File(sourcePath).delete();
1

There are 1 answers

3
Andy Brown On BEST ANSWER

It means there is still at least one open file handle on the file. When the last handle has been closed then the hidden file will be deleted.

You say that they disappear when you kill your server, therefore your server still has at least one handle open on to the file. You can use the lsof command to prove that it is indeed your server that has the open handle.

Check very carefully that you are closing all open streams on to the file in your java in both the success and exception cases.