【发布时间】:2012-03-20 09:02:41
【问题描述】:
我的机器上本地的 excel 文件很少。我想将此excel文件上传到ftp。我正在使用 apache commons FTPClinet。但是当它上传文件时,它已损坏并且大小为零。这是示例程序
谁能指出我哪里做错了?
public class App {
private static final String server = "localhost";
private static final String username = "test";
private static final String password = "test";
private static final String directory = "/home/files";
public static void main(String[] args) throws SocketException, IOException {
FTPClient f = new FTPClient();
f.connect(server);
f.login(username, password);
f.setFileType(FTPClient.BINARY_FILE_TYPE);
InputStream is = null;
is = new FileInputStream("c:\\tmp\\output.xls");
Boolean isStored = f.storeFile("status.xls", is);
is.close();
}
}
【问题讨论】:
-
我没有收到任何错误消息,唯一的问题是文件已损坏并且没有写入数据
-
你能发布你的错误吗?
-
您确定
/home/files/status.txt在FTP 服务器目录结构的上下文中有效吗?这看起来像是在服务器的文件存储根目录下可能无效的绝对路径。 -
查看更新后的代码,它现在正在生成一个 excel 文件,但仍然有一些不可读的字符损坏