如何直接从一个.zip文件读取文件,而无需在Android中提取它 [英] How to read a file directly from a .zip file without extracting it in android
问题描述
我一直在Android在过去的几个月里,现在我的问题是读取放在SD卡的.zip文件。我已经成功地完成了编码下载对SD卡的.zip文件。
我已经下载到SD卡img.zip文件。这img.zip包含5个图像文件。而不是解压img.zip我可以直接读取其内容现在...?如果是plz帮助。我看见几个例子在互联网,但他们都说解压缩,然后用,我想避免的那部分,因为我只是想设置图片为ImageView的。
ImageView的IMV =新ImageView的(本);
imv.setImageURI(Uri.parse(// SD卡/ 1.png));
这是如下载一张照片,并设置IMV其实际工作的源泉。现在我想的是什么,如下图所示。
imv.setImageURI(Uri.parse(// SD卡/ img.zip / 1.png));
我想这一点,但在我的布局我看不到图像。
能不能做到?plz帮助...
我得到了它由以下code工作....
{尝试
位图mBackground = NULL;
FIS的FileInputStream =新的FileInputStream(// SD卡/ tp.zip);
ZipInputStream ZIS =新ZipInputStream(FIS);
ZipEntry的泽= NULL;
而((ZE = zis.getNextEntry())!= NULL){
如果(ze.getName()。等于(1.png)){
Toast.makeText(CON,发现,2).show();
mBackground = BitmapFactory.de codeStream(ZIS);
imv.setImageBitmap(mBackground);
打破;
}
}
}赶上(FileNotFoundException异常五){
e.printStackTrace();
}赶上(IOException异常五){
e.printStackTrace();
}
尝试
imv.setImageURI(Uri.parse(// SD卡/ img.zip /1.png!));
I have been working on android for the past few months, now the problem for me is to read a .zip file placed on sdcard. I have successfully done the coding for downloading the .zip file on the sdcard.
I have img.zip file downloaded on to the sdcard. This img.zip contains 5 image files. Now instead of unzipping the img.zip can i directly read its content...??? if yes plz help. I saw few examples over internet but they all say to unzip and then use, i want to avoid that part because i simply want to set the images for an imageview.
ImageView imv = new ImageView(this);
imv.setImageURI(Uri.parse("//sdcard/1.png"));
this is like downloading a single image and setting the source of imv which actually works. Now what i want is something as shown below.
imv.setImageURI(Uri.parse("//sdcard/img.zip/1.png"));
I tried this, but in my layout i don't see the images.
can it be done... plz help...
I got it working by the following code....
try {
Bitmap mBackground=null;
FileInputStream fis = new FileInputStream("//sdcard/tp.zip");
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry ze = null;
while ((ze = zis.getNextEntry()) != null) {
if (ze.getName().equals("1.png")) {
Toast.makeText(con, "Found", 2).show();
mBackground = BitmapFactory.decodeStream(zis);
imv.setImageBitmap(mBackground);
break;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Try
imv.setImageURI(Uri.parse("//sdcard/img.zip!/1.png"));
这篇关于如何直接从一个.zip文件读取文件,而无需在Android中提取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!