问题
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