2011-12-29 90 views
5

我在过去的几个月中一直在研究android,现在我的问题是读取放置在SD卡上的.zip文件。我已经成功完成了在SD卡上下载.zip文件的编码。如何直接从.zip文件读取文件,而无需在android中提取它

我有img.zip文件下载到SD卡上。这img.zip包含5个图像文件。现在,而不是解压缩img.zip我可以直接阅读它的内容...?如果是的话,请帮忙。我在互联网上看到了一些例子,但他们都说要解压缩然后使用,我想避免这一部分,因为我只是想设置图像的图像。

ImageView imv = new ImageView(this); 
imv.setImageURI(Uri.parse("//sdcard/1.png")); 

这就像下载一个图像和设定IMV其实际工作的源泉。现在我想要的是如下所示。

imv.setImageURI(Uri.parse("//sdcard/img.zip/1.png")); 

我试过这个,但在我的布局中我看不到图像。

能不能做到?plz帮助...

我把它通过下面的代码工作....

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(); 
       } 

回答

2

尝试

imv.setImageURI(Uri.parse("//sdcard/img.zip!/1.png")); 
+0

@ MahdeTo-谢谢对于答复,但它不起作用布局没有任何图像打开。究竟是什么!符号的意思.. – AMUL 2011-12-29 05:53:21

+0

我很抱歉,您需要指定jar的协议:file:开头。 – MahdeTo 2011-12-29 06:41:34

+0

!意味着从这个zip或jar文件中访问此路径 – MahdeTo 2011-12-29 06:41:52