FD-Do 2017-08-15 02:55 采纳率: 0%
浏览 2896

java访问nfs,根目录下文件夹没办法进入

最近在实验使用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");
    }
    }

  • 写回答

3条回答 默认 最新

  • threenewbee 2017-08-15 15:54
    关注

    文件夹设置了正确的权限了没有,另外你是网络路径?要先建立共享连接。

    评论

报告相同问题?

悬赏问题

  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)