小编Ana*_*nth的帖子

Android FTPClient - retrieveFileStream()始终返回null

我是Android的新手.我正在尝试使用Apache Commons FTPClient将文件从ftp服务器下载到SD卡.行 InputStream input = client.retrieveFileStream("/"+ fileName); 始终返回null.但该文件位于Ftp位置.请帮助我知道错误在哪里.

我在清单中设置了以下权限; android:name ="android.permission.INTERNET"和android:name ="android.permission.WRITE_EXTERNAL_STORAGE"

我的守则

private static void downLoad(){
    FTPClient client = new FTPClient();
    FileOutputStream fos = null;

    try {
        client.connect("ftp.doamin.com");
        client.login("8888", "8888");
String filePath = "/mnt/sdcard/download/CheckboxHTML.txt" ;
String fileName = "CheckboxHTML.txt";
fos = new FileOutputStream(filePath);
InputStream input = client.retrieveFileStream("/" + fileName);
byte[] data = new byte[1024];
int count  = input.read(data); 
while ((count = input.read(data)) != -1) {
      fos.write(data, 0, count);
}
fos.close();
      if(!client.completePendingCommand()) { 
      client.logout(); 
      client.disconnect(); 
      System.err.println("File transfer failed."); 
} …
Run Code Online (Sandbox Code Playgroud)

android ftp-client apache-commons-net

3
推荐指数
1
解决办法
9597
查看次数

标签 统计

android ×1

apache-commons-net ×1

ftp-client ×1