Java URLConnection openStream()FileNotFoundException

时间:2013-09-25 05:03:31

标签: java filenotfoundexception urlconnection

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

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时,我可以检索该文件。请帮忙。

0 个答案:

没有答案