【发布时间】:2013-05-30 11:47:25
【问题描述】:
我正在尝试使用 apache commons 将目录中的所有文件下载到我的本地计算机,如下所示:
import java.io.FileOutputStream;
import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPFile;
public class FTPExample {
public static void main(String[] args) throws SocketException, IOException {
FTPClient client = new FTPClient();
client.connect("MyHostName");
client.enterLocalPassiveMode();
client.login("username", "password");
FTPFile[] files = client.listFiles("/App/");
for (FTPFile file : files) {
System.out.println(file.getName());
FileOutputStream fos = new FileOutputStream("Ftp Files/" + file.getName());
client.retrieveFile(file.getName(),fos);
}
}
}
我能够列出目录中的文件,但在尝试下载文件时出现 FilenotFound 异常。请帮忙。 我的错误是:
Exception in thread "main" java.io.FileNotFoundException: Ftp Files\01 (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:104)
at ftpexample.FTPExample.main(FTPExample.java:30)
Java Result: 1
编辑:我需要将文件以其原始文件名存储在文件夹 Ftp 文件/中。
【问题讨论】:
-
本地机器上的文件夹好像不存在。
-
没有,相信我。
标签: java apache ftp-client