免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Android程序解壓縮zip文件,并加載顯示解壓后的文件內容

剛做了個demo用于解壓縮本地zip文件,并用webview顯示其中的一個html文件,直接上代碼,需要的朋友可以看看

  1. public class ZipActivity extends Activity {  
  2.     private static final String TAG = "HelloXmlActivity";  
  3.     private WebView mWebView;    
  4.   
  5.     private static LinkedHashMap<String, String> widgetInfoMap = new LinkedHashMap<String, String>();  
  6.   
  7.     //http://blog.csdn.net/com360/article/details/6618086  
  8.     /** Called when the activity is first created. */  
  9.     @Override  
  10.     public void onCreate(Bundle savedInstanceState) {  
  11.         super.onCreate(savedInstanceState);  
  12.         setContentView(R.layout.main);  
  13.         String zipfile = "/sdcard/abc.zip";  
  14.         try {  
  15.             unzip(zipfile, "/sdcard/");//yangguangfu/wujiali/  
  16.               
  17.               
  18.         } catch (Exception e) {  
  19.             // TODO Auto-generated catch block  
  20.             e.printStackTrace();  
  21.               
  22.         }  
  23.           
  24.         mWebView=(WebView)findViewById(R.id.web);  
  25.         mWebView.loadUrl("file:///sdcard/abc/aaa.html");//此處加載解壓后的html內容  
  26.   
  27.     }  
  28.   
  29.     /* 
  30.      * 這個是解壓ZIP格式文件的方法 
  31.      *  
  32.      * @zipFileName:是傳進來你要解壓的文件路徑,包括文件的名字; 
  33.      *  
  34.      * @outputDirectory:選擇你要保存的路勁; 
  35.      *  
  36.      */  
  37.     private void unzip(String zipFileName, String outputDirectory)  
  38.             throws Exception {  
  39.         ZipInputStream in = new ZipInputStream(new FileInputStream(zipFileName));  
  40.         ZipEntry z;  
  41.         String name = "";  
  42.         String extractedFile = "";  
  43.         int counter = 0;  
  44.   
  45.         while ((z = in.getNextEntry()) != null) {  
  46.             name = z.getName();  
  47.             Log.d(TAG, "unzipping file: " + name);  
  48.             if (z.isDirectory()) {  
  49.                 Log.d(TAG, name + "is a folder");  
  50.                 // get the folder name of the widget  
  51.                 name = name.substring(0, name.length() - 1);  
  52.                 File folder = new File(outputDirectory + File.separator + name);  
  53.                 folder.mkdirs();  
  54.                 if (counter == 0) {  
  55.                     extractedFile = folder.toString();  
  56.                 }  
  57.                 counter++;  
  58.                 Log.d(TAG, "mkdir " + outputDirectory + File.separator + name);  
  59.             } else {  
  60.                 Log.d(TAG, name + "is a normal file");  
  61.                 File file = new File(outputDirectory + File.separator + name);  
  62.                 file.createNewFile();  
  63.                 // get the output stream of the file  
  64.                 FileOutputStream out = new FileOutputStream(file);  
  65.                 int ch;  
  66.                 byte[] buffer = new byte[1024];  
  67.                 // read (ch) bytes into buffer  
  68.                 while ((ch = in.read(buffer)) != -1) {  
  69.                     // write (ch) byte from buffer at the position 0  
  70.                     out.write(buffer, 0, ch);  
  71.                     out.flush();  
  72.                 }  
  73.                 out.close();  
  74.             }  
  75.         }  
  76.   
  77.         in.close();  
  78.   
  79.     }  
  80.   
  81.       
  82. }  


其中我的abc.zip文件是放在sdcard中的,里面有2個文件,解壓后生成一個abc文件夾,文件夾下是解壓縮后的2個文件,我用一個webview直接指定加載了解壓后的一個html文件,做的比較粗糙,省去了文件存在判斷,掃描文件名、文件類型,main.xml文件也很簡單,通過上面代碼應該可以看出其中的控件,這里不再寫xml布局文件了。


更多信息可參考下面文章:

加載html與js:

http://blog.csdn.net/com360/article/details/6618086

解壓縮zip文件

http://www.oschina.net/code/snippet_4873_4142





本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C#生成ZIP壓縮包
如何將文件打成zip包并下載
Android中讀取zip文件
java入門:怎樣取得class文件的路徑|中國IT實驗室
解壓zip文件
Java創(chuàng)建ZIP壓縮文件
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服