请问如何实现JAVA获取FTP文件大小以及文件修改时间?
或者,不实现上面的,直接判断远程FTP服务器的指定目录是否为空也可以。望高手帮帮小弟~~~

解决方案 »

  1.   


    public ArrayList getNameList() {
    System.out.println("正在获取文件列表...");
    ArrayList arraylist = null;
    try {
    BufferedReader dr = new BufferedReader(new InputStreamReader(client
    .nameList(path)));
    arraylist = new ArrayList();
    String s = "";
    while ((s = dr.readLine()) != null) {
    arraylist.add(s);
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    return arraylist;
    }这个是我获取服务器指定目录的文件列表的方法。下面是我的问题:
    当服务器的文件夹内不为空时,程序执行正常。但若FTP文件夹为空,那么就抛出“ 550 Can't find file”的异常。异常指向“new InputStreamReader(client.nameList(path)));”这里。我试过在catch和finally中都加入return arraylist,但是程序执行到这里,文件夹一为空,就抛出异常并终止了。 
    我不明白是为什么,我只想如果FTP文件夹内没有文件,就返回一个空的arraylist……
      

  2.   

    finally应该能执行吧,怎么终止也不会跳过finally的呀。如果没catch住,你看看只catch exption而不是IOException试试。
      

  3.   

    答:client.nameList(path)这个API的详细信息,楼主能否贴一下.这是问题的关键.
      

  4.   

    答:即:nameList(path)这个方法的信息或代码能否贴一下?
      

  5.   

    不晓得你的client.nameList(path)是什么意思
    写段我以前写的一个FTP客户端的代码 Socket server = new Socket(ip, port);//连接数据通道
    execute("LIST");//执行列表命令
    InputStreamReader isr = new InputStreamReader(server.getInputStream(), "GBK");//输入流
    BufferedReader br = new BufferedReader(isr);
    ArrayList<String> fileList = new ArrayList<String>();//文件列表
    String s;
    while ((s = br.readLine()) != null) {
    if (!s.endsWith(".")) {
    fileList.add(s);
    }
    }