0
私はいくつかの.zipファイルをダウンロードしていますが、解凍しようとすると「データエラー」が発生します。今はダウンロードしたファイルを見て、元の。これがエラーの原因になりますか?解凍するファイルのダウンロードコードがオリジナルよりも大きいファイルをダウンロードします
URL=intent.getStringExtra("DownloadService_URL");
FileName=intent.getStringExtra("DownloadService_FILENAME");
Path=intent.getStringExtra("DownloadService_PATH");
try{
URL url = new URL(URL);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
lenghtOfFile/=100;
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(Path+FileName);
byte data[] = new byte[1024];
long total = 0;
int count = 0;
while ((count = input.read(data)) != -1) {
output.write(data);
total += count;
notification.setLatestEventInfo(context, contentTitle, "Starting download " + FileName + " " + (total/lenghtOfFile), contentIntent);
mNotificationManager.notify(1, notification);
}
output.flush();
output.close();
input.close();
コード:
コードは、ファイルをダウンロードする
try {
String zipFile = Path + FileName;
FileInputStream fin = new FileInputStream(zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
UnzipCounter++;
if (ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(Path
+ ze.getName());
while ((Unziplength = zin.read(Unzipbuffer)) > 0) {
fout.write(Unzipbuffer, 0, Unziplength);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
File f = new File(zipFile);
f.delete();
notification.setLatestEventInfo(context, contentTitle, "File successfully downloaded", contentIntent);
mNotificationManager.notify(1, notification);
} catch (Exception e) {
notification.setLatestEventInfo(context, contentTitle, "Problem in downloading file ", contentIntent);
mNotificationManager.notify(1, notification);
}
}
解凍proccessを開始したが、そのエラーといくつかのファイルを抽出した後に停止します..私はanothe Rの.zipファイルを試してみました私はCRCエラーが発生しました..私は両方の.zipファイルをwinrarでテストしました..
元のファイルサイズ:3.67mb ..ダウンロードファイルサイズ:3.93mb
。あなたはいつもあなたが読んでどのくらいのデータをチェックせずにディスクへの完全なバイト配列を書き込むをも視野何< 1500byte(すなわち通常のイーサネットMTU)のパフォーマンスの観点から
これらの問題を解決する方法を教えてください。 – Omar
'output.write(data)'を 'output.write(data、0、count)'に置き換えてください。 –