我是安卓新手。我正在尝试使用 Apache Commons FTPClient 将文件从 ftp 服务器下载到 sdcard。行 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.");
}
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
感谢您的时间和兴趣。阿南特。