4

我正在尝试通过与 ftp 服务器的 URL 连接来访问文件。我用来检索文件并读取的代码是:

URL ftpurl = new URL("ftp://username:password@xxx.xxx.xxx.xxx/home/appuser/LoginCheck/cpuLive.log");
URLConnection connection = ftpurl.openConnection();
connection.connect();
InputStream input = new BufferedInputStream(ftpurl.openStream());
System.out.println(input);

但我得到一个 FileNotFound 异常:

Exception in thread "main" java.io.FileNotFoundException: home/appuser/LoginCheck/cpuLive.log
    at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(Unknown Source)
    at java.net.URL.openStream(Unknown Source)
    at com.djblogin.codes.ProcessAll.processLogin(ProcessAll.java:413)
    at com.djblogin.codes.ProcessAll.processOperations(ProcessAll.java:39)
    at com.djblogin.codes.LoginCheck.main(LoginCheck.java:14)

当我在浏览器中提供相同的 URL 时,我可以检索该文件。请帮忙。

4

0 回答 0