Java : How to access UNC location

眉间皱痕 提交于 2019-12-11 03:17:51

问题


same as title; how to access to UNC location in ShareFolder?

URL uri = new URL("file:\\\\x.x.1.10\\myUNC");
File file = new File(uri);

or

URL uri = new URL("file://x.x.1.10/myUNC");
File file = new File(uri);

also doesn't works.


回答1:


Just:

File f = new File("\\\\x.x.1.10\\myUNC");



回答2:


Using forward slashes (/) instead of backslashes with the file protocol will work to access a UNC location:

URI uri = URI.create("file:////SERVER/some/path");

Be sure, however, not to call URI.normalize() or URI.resolve() or it will break the UNC URI by removing too many slashes. The official bug: URI.normalize() ruins URI built from UNC File

More on UNC paths in java



来源:https://stackoverflow.com/questions/41926148/java-how-to-access-unc-location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!