我正在尝试通过 ftp 下载文件,但retrieveFileStream 返回 null,我已检查 getReplyString 并返回 200,这是我的代码:
File file = new File(this.config.getDestDirectory() + File.separator + fileName);
String t = this.ftp.getReplyString();
InputStream in = this.ftp.retrieveFileStream(fileName);
FileOutputStream fos = new FileOutputStream(file);
StreamUtils.copy(in, fos);
in.close();
fos.close();
有什么建议吗?
非常感谢您。
最佳答案
尝试这种方式..这是我的代码库中的一个示例,我使用了开源 Apache commons-net-ftp-2.0。
public void goforIt()
{
FTPClient con = null;
try
{
con = new FTPClient();
con.connect("10.0.0.1"); // Dummy address
if (con.login("Administrator", "KUjWbk361wobbyl"))
{
con.enterLocalPassiveMode(); // important!
con.setFileType(FTP.BINARY_FILE_TYPE);
String data = "/sdcard/2prerakm4a.m4a";
OutputStream out = new FileOutputStream(new File(data));
boolean result = con.retrieveFile("prerakm4a.m4a", out);
out.close();
if (result) Log.v("download result", "succeeded");
con.logout();
con.disconnect();
}
}
catch (Exception e)
{
Log.v("download result","failed");
e.printStackTrace();
}
}
关于java - 输入流返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10993827/