Reputation: 49
I have a network drive mapped as:
net use h: \ip\servername
I have a normal java application that is going to read a txt file from that drive.
Code:
File file = new File("H:\\MyFile.txt");
try {
byte[] bytes = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
} catch (IOException ex) {
Logger.getLogger(JavaApplication25.class.getName()).log(Level.SEVERE, null, ex);
}
When i run this program from my computer (windows 7 or from another computer with windows vista), the program runs without any problem.
However, when i run this program from a computer with Windows 10, i get the following error:
java.nio.file.NoSuchFileException: H:\MyFile.txt
But if i run the application using the following code it works:
File file = new File("\\ip\servername\MyFile.txt");
try {
byte[] bytes = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
} catch (IOException ex) {
Logger.getLogger(JavaApplication25.class.getName()).log(Level.SEVERE, null, ex);
}
How can i use the mapped drive letter instead of using the full address?
Upvotes: 3
Views: 8087
Reputation: 31
Got same issue. Resolved by editing windows registry
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"EnableLinkedConnections"=dword:00000001
If it works, it means your IT dept. should manage better network policies.
Upvotes: 3