問題描述
以下代碼用于獲取文件(任何文件都可以,但現在我只是使用圖像),并將其上傳到我的服務器(有效,等等等等).唯一的問題是圖片在傳輸后相當傾斜.主要的建議是使用FTPClient的setFileTranferMode到FTPClient.BINARY_FILE_TYPE,這個……此時沒有效果……
The following code is meant to take a file (any file would be nice, but right now I'm just using images anyway), and upload it to my server (which works, blah blah blah). The only problem is that the picture is quite skewed after transfer. The main suggestion is to use FTPClient's setFileTranferMode to FTPClient.BINARY_FILE_TYPE, which... has no effect at this point...
這是該方法的代碼:
public void sendFile(File sendMe) throws IOException{
f.connect(ip);
f.login(username, password);
String recipient=null;
while(!f.changeWorkingDirectory(path+recipient)){
recipient=JOptionPane.showInputDialog("What is the name of the computer you are sending this to?");
}
f.changeWorkingDirectory(path+recipient);
f.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
f.storeFile(sendMe.getName(), new BufferedInputStream(new FileInputStream(sendMe)));
System.out.println("Stored!");
f.disconnect();
System.out.println("Uploaded");
}
一如既往,我們將不勝感激任何幫助!謝謝!
As always, any help would be much appreciated! Thanks!
推薦答案
您沒有使用正確的方法來設置文件類型.您應該使用 setFileType 代替.
You are not using the correct method to set the file type. You should use setFileType instead.
f.setFileType(FTPClient.BINARY_FILE_TYPE);
這篇關于FTPClient 的 setFileTransferMode 不生效的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!