我在2.3.3上創建了一個Android項目,並在移動設備2.3.3上嘗試了它,一切正常。它不適用於移動4,所以我重新構建了Android 4,但我有同樣的問題。Android應用程序無法在Android上運行4
這是代碼:
public void FTP_Download(){
String server = "192.168.1.135";
int port = 21;
String user = "pc1";
String pass = "1551";
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
Toast.makeText(getBaseContext(), "download starting.",Toast.LENGTH_LONG).show();
// APPROACH #1: using retrieveFile(String, OutputStream)
String remoteFile1 = "i.xml";
File downloadFile1 = new File("sdcard/i.xml");
OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
outputStream1.close();
if (success) {
Toast.makeText(getBaseContext(), "File #1 has been downloaded successfully.",Toast.LENGTH_LONG).show();
}
} catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
ex.printStackTrace();
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
注:
我使用commons-淨3.1連接。
您應該爲您的問題添加堆棧跟蹤。我假設你不**在UI線程上調用你的'FTP_Download()'函數? – Jens
什麼是日誌跟蹤輸出,其次最好使用ExtenalStorageDirecory調用來讀取寫入SD卡 – Orlymee