How to Open a Unc Path from Linux in Java

How can I open a UNC path from Linux in Java?

Have a look at jcifs. It sounds like what you are looking for.

From the jcifs site:

JCIFS is an Open Source client library that implements the CIFS/SMB networking protocol in 100% Java. CIFS is the standard file sharing protocol on the Microsoft Windows platform (e.g. Map Network Drive ...). This client is used extensively in production on large Intranets.

Connecting to password protected UNC using Java

JCIFS is an Open Source client library that implements the CIFS/SMB networking protocol in 100% Java.

Creating a file from a file path that can be opened in Linux


  1. Check the file already exists at this path filePath

  2. /home/ur/Desktop/out.txt should be something like the path in Linux, starting with / in case your path is absolute.

  3. For Java, every platform is same, you need not to worry about Linux/Windows (except for giving file path). All methods should work fine in all Platforms though.

  4. You can make use of file.exists() which will provide boolean return value in order to have your conditions. true if file exists & false otherwise.

Java file path in Linux

Looks like you are missing a leading slash. Perhaps try:

Scanner s = new Scanner(new File("/home/me/java/ex.txt"));

(as to where it looks for files by default, it is where the JVM is run from for relative paths like the one you have in your question)



Related Topics



Leave a reply



Submit