0
(首先,我在這裏新,我的英語不太好,所以我想道歉我的壞寫作技巧)安卓解壓縮文件從ftp扔「數據錯誤」和「CRC不匹配」錯誤
我正在從Android公司的FTP服務器上讀取一些.zip文件並從中獲取內容。我使用org.apache.commons.net.ftp庫連接到ftp。
我可以列出來自服務器的所有.zip文件,但是當我嘗試列出內容時,我開始出現問題。有些文件很好,但在某些情況下,我無法讀取整個zip內容。
這是我用來連接到FTP部分代碼:
private static final String TAG = "MyFTPClient";
public FTPClient mFTPClient = null;
//Method to connect to FTP server:
public boolean ftpConnect(String host, String username, String password, int port) {
try {
mFTPClient = new FTPClient();
// connecting to the host
mFTPClient.connect(host);
// now check the reply code, if positive mean connection success
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
// login using username & password
boolean status = mFTPClient.login(username, password);
/* Set File Transfer Mode
*
* To avoid corruption issue you must specified a correct
* transfer mode, such as ASCII_FILE_TYPE, BINARY_FILE_TYPE,
* EBCDIC_FILE_TYPE .etc. Here, I use BINARY_FILE_TYPE
* for transferring text, image, and compressed files.
*/
mFTPClient.setFileType(FTP.ASCII_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
return status;
}
} catch(Exception e) {
Log.d(TAG, "Error: could not connect to host " + host);
Log.d(TAG, e.toString());
}
return false;
}
這是我使用列出從.zips文件的名稱代碼:
public ArrayList<String> ftpZipRetrieveFilesTitles(String filePath) throws IOException{
ZipInputStream zis = null;
ArrayList<String> fitxIzenak = new ArrayList<String>();
try {
zis = new ZipInputStream(mFTPClient.retrieveFileStream(filePath));
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
String filename = ze.getName();
fitxIzenak.add(filename);
}
zis.close();
mFTPClient.completePendingCommand();
return fitxIzenak;
} catch (Exception e) {
zis.close();
mFTPClient.completePendingCommand();
e.printStackTrace();
}
return fitxIzenak;
}
而這就是我得到:
java.util.zip.ZipException: CRC mismatch
at java.util.zip.ZipInputStream.readAndVerifyDataDescriptor(ZipInputStream.java:208)
at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:172)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:225)
at com.example.services.MyFTPClient.ftpZipRetrieveFromFiles(MyFTPClient.java:250)
at com.example.gipuzkoabidaian.MainActivity$FTPkonexioa.doInBackground(MainActivity.java:965)
at com.example.gipuzkoabidaian.MainActivity$FTPkonexioa.doInBackground(MainActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
java.util.zip.ZipException: data error
at java.util.zip.ZipInputStream.read(ZipInputStream.java:340)
at libcore.io.Streams.skipByReading(Streams.java:158)
at java.util.zip.InflaterInputStream.skip(InflaterInputStream.java:217)
at libcore.io.Streams.skipAll(Streams.java:133)
at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:152)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:225)
at com.example.services.MyFTPClient.ftpZipRetrieveFilesTitles(MyFTPClient.java:303)
at com.example.gipuzkoabidaian.MainActivity$FTPkonexioa.doInBackground(MainActivity.java:961)
at com.example.gipuzkoabidaian.MainActivity$FTPkonexioa.doInBackground(MainActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
我希望有人能幫助我,我不知道該怎麼辦。