问题描述
以下代码旨在获取一个文件(任何文件都不错,但是现在无论如何我都只是使用图像),然后将其上传到我的服务器上(有效,等等).唯一的问题是图像在传输后非常歪斜.主要建议是使用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不生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!