0
我使用下面的代碼從ftp下載XML文件到android手機內存使用我能夠連接ftp,但同時檢索XML到本地內存它給出以下異常07-19 15:01:03.721:DEBUG/SntpClient(61) :請求時間失敗:java.net.SocketException異常:地址家族不受協議 支持請幫助別人感謝你,如何使用下面的android代碼從ftp下載xml文件?
Java類
private void fnfileDownloadBuf()
{
FTPClient client = new FTPClient();
FileOutputStream fos = null;
try {
//client.connect("ftp://ftp.qualityinaction.net/QIA/Questions/Airlines/");
client.connect("ftp.qualityinaction.net");
client.login("qualityinaction.net","password");
client.setFileType(FTP.BINARY_FILE_TYPE);
//
// The remote filename to be downloaded.
//
// String filename = "/QIA/Questions/Airlines/index.xml";
String filename = getFilesDir().getAbsolutePath()+ File.separator + "/index.xml";
// String filename = "/QIA/Questions/Airlines/index.xml";
File file = new File(filename);
fos = new FileOutputStream(file);
//
// Download file from FTP server
//
//client.retrieveFile("/" + filename, fos);
client.retrieveFile("/QIA/Questions/Airlines/index.xml;type=i", fos);
// client.retrieveFile(getFilesDir().getAbsolutePath()+ File.separator + "/index.xml", fos);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
清單XML文件
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
異常
exception 07-19 15:01:03.721: DEBUG/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol
複製和粘貼在谷歌搜索框中鍵入錯誤 – Randroid
感謝響應,我試過我沒有收到任何東西,請檢查並告訴我解決方案 –