Android 下载zip文件并将其保存在SD卡中
我有一个应用程序下载zip文件并保存到SD卡。但是我在读取inputstream时得到了Android 下载zip文件并将其保存在SD卡中,android,zipinputstream,Android,Zipinputstream,我有一个应用程序下载zip文件并保存到SD卡。但是我在读取inputstream时得到了zipentry=null,它没有进入while块。有人能帮我解决这个问题吗 try { // fileInputStream = new InputStream(input); ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputSt
zipentry=null
,它没有进入while块。有人能帮我解决这个问题吗
try {
// fileInputStream = new InputStream(input);
ZipInputStream zipInputStream
= new ZipInputStream(new BufferedInputStream(input));
ZipEntry zipEntry=zipInputStream.getNextEntry();
Toast.makeText(getApplicationContext(), "I have entered try block zipentry"+zipEntry,Toast.LENGTH_LONG).show();
System.out.println("Zipentry is"+zipEntry);
while ((zipEntry = zipInputStream.getNextEntry()) != null){
Toast.makeText(getApplicationContext(), "Entered into while block",Toast.LENGTH_LONG).show();
String zipEntryName = zipEntry.getName();
File file = new File(to + zipEntryName);
if (file.exists()){
} else {
if(zipEntry.isDirectory()){
file.mkdirs();
}else{
byte buffer[] = new byte[BUFFER_SIZE];
FileOutputStream fileOutputStream = new FileOutputStream(file);
bufferedOutputStream
= new BufferedOutputStream(fileOutputStream, BUFFER_SIZE);
int count;
while ((count
= zipInputStream.read(buffer, 0, BUFFER_SIZE)) != -1) {
bufferedOutputStream.write(buffer, 0, count);
}
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
}
zipInputStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "File not found",Toast.LENGTH_LONG).show();
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "Input outout error",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
您已经有一个
ZipEntry-ZipEntry=zipInputStream.getnextery()代码>while循环中的before条件。忽略它,只在while循环中初始化它。比如:
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null){
//
}
不,只是为了检查Zipentry的值,我之前初始化了它,通过它我知道这个值是空的