本文介紹了FTPClient - Java,上傳文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試進行非常簡單的文件上傳.我想要一個可以上傳我告訴它的任何文件的 Java FTPClient.但是 pdf 總是一團糟,我的 pdf 編輯器 (Adobe) 不會打開它,說存在 I/O 錯誤.
I'm trying to do a VERY simple file upload. I want a Java FTPClient that can upload any file I tell it to. But the pdf always gets all messed up and my pdf editor (Adobe) won't open it, saying there is an I/O error.
我正在使用以下類:
import org.apache.commons.net.ftp.FTPClient;
....
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("mydomain.com");
client.login("user", "password");
String filename = "myPDF.pdf";
fis = new FileInputStream(filename);
client.storeFile("temp.pdf", fis);
fis.close();
client.logout();
} catch (IOException e) {
e.printStackTrace();
}
為什么這不起作用,我該如何解決?
Why doesn't this work, and how do I fix it?
推薦答案
因為 FTPClient 是 FTP.ASCII_FILE_TYPE
.您只需要更新配置即可以二進制模式傳輸.
It doesn't work because the default transfer mode for FTPClient is FTP.ASCII_FILE_TYPE
. You just need to update the configuration to transfer in binary mode.
這篇關于FTPClient - Java,上傳文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!