私はAndroidの初心者です。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();
}
}
お時間と関心をお寄せいただきありがとうございます。アナント。