Java FTP xls文件上传
我正在尝试将文件上传到 Java 类中的 FTP 服务器。 我使用 apache 库:org.apache.commons.net.ftp.FTPClient。 上传功能工作正常,直到我尝试上传 XLS (Excel) 文件。 特别是,当我上传时,文件已上传,但似乎已损坏。事实上,它的大小与原始大小不同,当我尝试打开它时,它无法正确打开并且不显示所有数据。
这是我使用的代码的一部分:
FTPClient ftpClient = new FTPClient();
File[] fileList;fileList = localFilePath.listFiles();
for (File file : fileList) {
String fileName = file.getName();
FileInputStream fileInputStream = new FileInputStream(file);
ftpClient.storeFile(fileName, fileInputStream);
fileInputStream.close();
}
非常感谢您的任何帮助。
I am trying to upload files to a FTP Server in a Java class.
I use apache library: org.apache.commons.net.ftp.FTPClient.
The upload function works fine until I try to upload a XLS (Excel) file.
In particular, when I upload it, the file is uploaded, but it seems to be corrupted. In fact its size is different from the original size and when I try to open it, it doesn't open correctly and doesn't show all the data.
Here is a portion from the code I use:
FTPClient ftpClient = new FTPClient();
File[] fileList;fileList = localFilePath.listFiles();
for (File file : fileList) {
String fileName = file.getName();
FileInputStream fileInputStream = new FileInputStream(file);
ftpClient.storeFile(fileName, fileInputStream);
fileInputStream.close();
}
Thank you very much for any kind of help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用此线程中的建议解决了问题:
Transfer raw binary with apache commons-net FTPClient?
我所需要做的就是为非 .txt 文件设置二进制文件模式:
I solved the problem using the suggestion in this thread:
Transfer raw binary with apache commons-net FTPClient?
All I needed to do was setting binary file mode for non .txt files: