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
Check the file already exists at this path
filePath
/home/ur/Desktop/out.txt
should be something like the path in Linux, starting with/
in case your path is absolute.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.
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
Is There an Java API Viewer on Command Line Like Man for C and Ri for Ruby
Growing Resident Size Set in Jvm
@Override Compile Error, Implementing an Interface (Eclipse Jdk1.6.0_23 Linux)
The Encoding 'Utf-8' Is Not Supported by the Java Runtime
Making a Java Package in the Command Line
How to Include Platform-Specific Native Libraries in the .Jar File Using Eclipse
Is a Java Filelock a Posix Advisory (Fcntl) Lock
Certificateexception: No Subject Alternative Names Present
Cassandra Startup Error 1.2.6 on Linux X86_64
Why Is Alternatives Command Used When Installing Java on a Linux MAChine
Seeing All the System Calls That Were Made by a Java Program
How to Call Method in Jar File with Terminal
Unsatisfiedlinkerror When Using Jni
Jfilechooser and Browsing Networked MAChines
Command Working in Terminal, But "No Closing Quote" Error When Used Process.Exec