FTPClient 的 setFileTransferMode 不生效

FTPClient#39;s setFileTransferMode Not Taking Effect(FTPClient 的 setFileTransferMode 不生效)
本文介绍了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 不生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android sdk 18 TextView gravity doesn#39;t work vertically(Android sdk 18 TextView 重力不能垂直工作)
Java android: appending a newline using TextView(Java android:使用 TextView 添加换行符)
How to create simple Android TextView and display text on it using java code?(如何使用 java 代码创建简单的 Android TextView 并在其上显示文本?)
Add opaque quot;shadowquot; (outline) to Android TextView(添加不透明的“阴影(大纲)到 Android TextView)
Android: Creating a Circular TextView?(Android:创建一个圆形 TextView?)
Android - set TextView TextStyle programmatically?(Android - 以编程方式设置 TextView TextStyle?)