本文介紹了Apache Commons Net FTPClient 中的文件名編碼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我必須將文件上傳到 FTP 服務(wù)器.文件名包含特殊字母,例如 ??ü
.在 FTP 服務(wù)器上,我需要將文件名進行 UTF-8 編碼.
I have to upload a file to an FTP server. The filename contains special letters, say ??ü
. On the FTP server, I need the filename to be UTF-8 encoded.
我的代碼是這樣的:
import org.apache.commons.net.ftp.FTPClient;
FTPClient client = new FTPClient();
...
boolean retval = client.storeFile(fileName, inputStream);
問題是在storeFile
之后,F(xiàn)TP服務(wù)器上保存的文件名是ISO-8859-1編碼而不是UTF-8.
The problem is that after storeFile
, the name of the file saved on the FTP server is ISO-8859-1 encoded rather than UTF-8.
如何告訴 FTPClient
對文件名進行 UTF-8 編碼?
How can I tell FTPClient
to UTF-8 encode the file names?
推薦答案
我沒測試過,你可以試試這個:
I have not tested it, but you can try this:
client.setControlEncoding("UTF-8");
這篇關(guān)于Apache Commons Net FTPClient 中的文件名編碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!