How to access network paths from Java on OSX?

I am trying to access a network folder / UNC path from Java on Mac OSX. On Windows, the following test program works fine (at least one of the tested paths):

public class PathTest { public static void main(String[] args) { for (String path : Arrays.asList( "\\\\myserver\\transfer", "//myserver/transfer", "file://myserver/transfer", "smb://myserver/transfer")) { File f = new File(path); System.out.println(path + ": " + f.getAbsolutePath() + ", " + f.exists()); Path p = Paths.get(path); System.out.println(path + ": " + p.toAbsolutePath() + ", " + Files.exists(p)); } } } 

folders cannot be found on Mac OS:

 \\myserver\transfer: /Users/tim/IdeaProjects/PathTest/\\myserver\transfer, false //myserver/transfer: /myserver/transfer, false file://myserver/transfer: /Users/tim/IdeaProjects/PathTest/file://myserver/transfer, false smb://myserver/transfer: /Users/tim/IdeaProjects/PathTest/smb://myserver/transfer, false 

When I use Finder, I can access the folder (using the guest user) using "smb: // myserver / transfer". What's wrong?

EDIT NIO test added. 2

+4
source share
1 answer

Either install the partition and access it like any local directory, or use a specialized library such as JCIFS or Apache Commons VFS .

+5
source

Source: https://habr.com/ru/post/1496134/


All Articles