I have simple Java program which reads a file and writes it on my console in eclipse tool. I'm
trying to execute the same java program to read the file on Remote Linux server. Please help how can I achieve it?
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args){
String path = "C:/tmp";
String file = "java2502201411.txt";
try
{
FileInputStream in = new FileInputStream(path + "/" + file);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while((strLine = br.readLine())!= null)
{
System.out.println(strLine);
}
}catch(Exception e){
System.out.println(e);
}
}
}
I'm able to call a file from other windows environment which is in network. for Eg: I'm trying to read a file on my windows network such as usmnp1804 terminal. String path = "//usmnp1804/C$/tmp". In the similar way I'm trying to read a file on Linux server but it is not working as intended, getting an error such as File not found Exception. I suspect such as my java program is not able to hit Linux server path. Please help. String path = "/home/jctadm/tmp".
Thanks Raj
Java can't natively open files shared across CIFS. You have to use a client library. JCIFS seems to be the de facto standard for this. Apache Commons Virtual File System also supports this. Both have tags here on SO: jcifs and apache-commons-vfs .
This example might help, this is a basic example to use VFS to retrieve files from a remote system using the SFTP protocol. Files matching a specified regular expression are retrieved.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.