Java: Accessing a File from an FTP Server

前端 未结 2 1507
醉酒成梦
醉酒成梦 2021-02-05 21:38

So I have this FTP server with a bunch of folders and files inside.

My program needs to access this server, read all of the files, and display their data.

For de

2条回答
  •  灰色年华
    2021-02-05 22:13

    File objects cannot handle an FTP connection, you need to use a URLConnection:

    URL url = new URL ("ftp://username:password@www.superland.example/server");
    URLConnection urlc = url.openConnection();
    InputStream is = urlc.getInputStream();
    ...
    

    Consider as an alternative FTPClient from Apache Commons Net which has support for many protocols. Here is an FTP list files example.

提交回复
热议问题