最近在实验使用java读取指定路径下的文件,发现没办法进入共享根目录下的文件夹
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import com.sun.nfs.XFileExtensionAccessor;
import com.sun.xfile.XFile;
import com.sun.xfile.XFileInputStream;
import com.sun.xfile.XFileOutputStream;
import com.sun.xfile.XFileWriter;
import net.sf.jftp.system.logging.Log;
import java.io.*;
/**
-
Created by fd on 2017/8/14.
*/
public class NFS {
String url;
XFile xfile;
public void NFSconnection(String ip,String dir)
{
url = "nfs://" + ip + "/" + dir;//创建连接
xfile = new XFile(url);
//调用exists()判断是否连接成功
if (xfile.exists()) {
System.out.println("URL is OK!");
} else {
System.out.println("URL is Bad!");
return;
}}
public void test(String pathname) throws IOException {
String[] fileList = xfile.list();//缺少这一句的话,会出现找不到文件的错误XFile temp = new XFile(url+"/"+pathname); XFileInputStream in = new XFileInputStream(temp); int lent = 0; byte[] buf = new byte[200]; while((lent = in.read(buf))>0){ System.out.println(new String(buf,0,lent)); }
}
public static void main(String[] args) throws IOException {
String ip ="172.19.152.32";
String dir = "nfs";
NFS nfs = new NFS();
nfs.NFSconnection(ip,dir);
nfs.test("ss");
}
}