I have in my java process code that opens a file for writing using Files.newOutputStream which is inside the try-with-resources statement. After I finishing writing the files (all written in the same way) and closed. They deleted together with the folder that files are inside of it.
String folder = "folder"
try(OutputStream out = Files.newOutputStream(Paths.get(folder + '/' + fileName), StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
//...
out.write(buffer);
//...
} catch(IOException excp) {
excp.printStackTrace();
}
FileUtils.forceDelete(new File(folder));
But, when I'm looking in the lsof (I'm running CentOS) I see that those files (and there could be 20k or 30k) are shown as (deleted) in lsof and means that they are open. I can't understand how closed file can remains open and eventually I get too many open file descriptors. So, I know that I can raise the limit, but I want to properly close or to make file closed instead of increasing limits.
Thanks !!!