I want to test if a file exists on a mounted network drive.
I wrote this simple code using File.exists
.
import java.io.File;
public class NetworkDrive {
public static void main(String[] args) {
System.err.println(new File("/Volumes/DATA/testedFile.txt").exists());
}
}
It works correctly mostly but i found an edge case where this code is problematic. If the drive was mounted and for some reason the network connection fails down, the program hangs for a very long time (10 minutes).
time java NetworkDrive
false
real 10m6.114s
user 0m0.431s
sys 0m0.949s
Even if i try to kill it using with a KILL
signal, the process is still running.
1875 ttys000 0:00.00 (java)
The problem is the same with java.nio
:
Files.exists(Paths.get("/Volumes/DATA/testedFile.txt"));
I use java version 1.8.0_20 on OS X Yosemite.