本文介绍了FTPClient 的 setFileTransferMode 不生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

05-18 22:55