I am trying to check if a certain java.io.File is open by an external program. On windows I use this simple trick:
try {
FileOutputStream fos = new FileO
This one should also work for Windows systems. But attention, does not work for Linux!
private boolean isFileClosed(File file) {
boolean closed;
Channel channel = null;
try {
channel = new RandomAccessFile(file, "rw").getChannel();
closed = true;
} catch(Exception ex) {
closed = false;
} finally {
if(channel!=null) {
try {
channel.close();
} catch (IOException ex) {
// exception handling
}
}
}
return closed;
}