[英]How to get the UNC path of a mapped network drive in a Java application
[英]How to access mapped network drive from java application?
我有一个网络驱动器映射为:
净使用h:\\ ip \\ servername
我有一个普通的Java应用程序,它将从该驱动器读取txt文件。
码:
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);
}
当我从计算机(Windows 7或具有Windows Vista的另一台计算机)运行此程序时,该程序运行没有任何问题。
但是,当我从装有Windows 10的计算机上运行此程序时,出现以下错误:
java.nio.file.NoSuchFileException: H:\MyFile.txt
但是,如果我使用以下代码运行该应用程序,它将起作用:
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);
}
如何使用映射的驱动器号而不使用完整地址?
有同样的问题。 通过编辑Windows注册表解决
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"EnableLinkedConnections"=dword:00000001
如果有效,则意味着您的IT部门。 应该管理更好的网络策略。
使用\\\\ ip \\ servername \\ file.txt起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.