本文介紹了FTPClient - Java,上傳文件的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我正在嘗試進(jìn)行非常簡(jiǎn)單的文件上傳.我想要一個(gè)可以上傳我告訴它的任何文件的 Java FTPClient.但是 pdf 總是一團(tuán)糟,我的 pdf 編輯器 (Adobe) 不會(huì)打開(kāi)它,說(shuō)存在 I/O 錯(cuò)誤.
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.
我正在使用以下類(lèi):
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?
推薦答案
因?yàn)?FTPClient 是 FTP.ASCII_FILE_TYPE
.您只需要更新配置即可以二進(jìn)制模式傳輸.
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.
這篇關(guān)于FTPClient - Java,上傳文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!