3

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?

11
  • the address is \\ip\sername, i forgot a \ Commented Mar 14, 2019 at 8:42
  • When I try your code with a mapped network drive it works fine. Are you sure the drive is mapped when you try to access it? Commented Mar 14, 2019 at 9:05
  • yes, it is mapped in all computers with the exact same letter before the execution Commented Mar 14, 2019 at 9:47
  • Which JRE/JDK are you using? Have you tried different ones? Commented Mar 14, 2019 at 9:48
  • in my pc : JRE: 1.8.0_161; JDK: jdk1.8.0_65; in the other computer: jre:1.8.0.201; JDK 1.8.0.201. Commented Mar 14, 2019 at 10:03

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

using \\ip\servername\file.txt worked

1 Comment

This is not an answer to the question the link you provide is not a mapped drive but a UNC address to a network drive. While they may seem to be the same - they are not. A mapped drive is a link to the physical connection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.