String path = "ftp://hz:[email protected]/qxtmp/wangjun-test.txt";
File file = new File(path);
long lastTime = file.lastModified();我调试的时候发现,路径在构造file的时候path变成了ftp:\hz:[email protected]\qxtmp\wangjun-test.txt
就这个路径我根本就访问不了这个文件,这是什么原因?

解决方案 »

  1.   

    修改了一下
    URI uri = new URI("ftp://hz:[email protected]/qxtmp/wangjun-test.txt");
    File file = new File(uri);报错
      

  2.   

    自己解决了
    下面就是如何取得ftp上面某个文件的修改时间:
    /**
     * 
     */
    package test;import java.io.File;
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.SocketException;
    import java.text.SimpleDateFormat;
    import java.util.Date;import org.apache.commons.net.ftp.FTPClient;
    import org.apache.commons.net.ftp.FTPFile;/**
     * @author hxj
     *
     */
    public class FtpTest { /**
     * @param args
     */
    public static void main(String[] args) { FTPClient client = new FTPClient();
    try {
    client.connect("134.98.8.214");
    boolean isLogin = client.login("hz", "hz");
    System.out.println(isLogin);
    if(!isLogin){
    client.disconnect();
    client = null;
    }
    FTPFile[] fileList = client.listFiles("qxtmp/wangjun-test.txt");
    for (int i = 0; i < fileList.length; i++) {
    System.out.println(new String(fileList[i].getName().getBytes("iso-8859-1"),"gbk"));
    System.out.println(fileList[i].getTimestamp().getTime().getTime());
    Date date = new Date(fileList[i].getTimestamp().getTime().getTime());
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
    dateFormat.format(date);
    System.out.println(dateFormat.format(date));
    }
    } catch (SocketException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
      

  3.   

    gx lz 自己解决才是王道
      

  4.   

    强烈呼吁楼主把FTPClient和FTPFile这两个类也贴出来看看
    此贴继续关注
      

  5.   


    FTPClient和FTPFile是Apache的开源包commons-net-1.4.1.jar里面的。
    http://commons.apache.org/net/