下面的代碼是爲了獲取一個文件(任何文件都不錯,但現在我只是使用圖片),並將其上傳到我的服務器(這工作,等等等等等等) 。唯一的問題是轉移後圖片偏斜。主要建議是使用FTPClient的setFileTranferMode到FTPClient.BINARY_FILE_TYPE,這......有在這一點上沒有任何影響......FTPClient的setFileTransferMode沒有生效
下面是該方法的代碼:
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");
}
與往常一樣,任何幫助將非常感謝!謝謝!
哇,我現在覺得自己聰明.....太謝謝你了! – J3RN 2012-02-10 00:34:05