Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access network paths from Java on OSX?

Tags:

java

macos

I try 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));
        }
    }
}

on Mac OS it fails to reach the folders:

\\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), by using "smb://myserver/transfer". What's wrong?

EDIT added NIO.2 test

like image 637
Tim Büthe Avatar asked Aug 09 '13 12:08

Tim Büthe


People also ask

How do I find Java path on Mac?

In macOS, the JDK installation path is /Library/Java/JavaVirtualMachines/jdk-10.

How do I access Java files on Mac?

Click on Apple icon on upper left of screen. Click on the Java icon to access the Java Control Panel.

How do you find the full file path on a Mac?

Show the path to a file or folder On your Mac, click the Finder icon in the Dock to open a Finder window. Choose View > Show Path Bar, or press the Option key to show the path bar momentarily. The location and nested folders that contain your file or folder are displayed near the bottom of the Finder window.


1 Answers

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

like image 129
Anthony Accioly Avatar answered Sep 27 '22 22:09

Anthony Accioly