What Is the Recommended Way of Accessing a Network Share Folder (Located in Windows or Linux) in Java

Java: Accessing Windows files from Linux machine

To access windows directory you should mount windows shared directory to your linux server.

See https://wiki.centos.org/TipsAndTricks/WindowsShares

After this you'll be able to use this windows directory as a local linux directory.

What is the best way to find the user's home directory in Java?

The bug you reference (bug 4787391) has been fixed in Java 8. Even if you are using an older version of Java, the System.getProperty("user.home") approach is probably still the best. The user.home approach seems to work in a very large number of cases. A 100% bulletproof solution on Windows is hard, because Windows has a shifting concept of what the home directory means.


If user.home isn't good enough for you I would suggest choosing a definition of home directory for windows and using it, getting the appropriate environment variable with System.getenv(String).

connecting to shared folder in windows with java

You should use SmbFile and NtlmPasswordAuthentication from JCIFS. Here is a simple piece of code to show you how to do :

String url = "smb://yourhost/yourpath/";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "user", "password");
SmbFile dir = new SmbFile(url, auth);
for (SmbFile f : dir.listFiles())
{
System.out.println(f.getName());
}


Related Topics



Leave a reply



Submit