最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Android如何實(shí)現(xiàn)不解壓直接讀取zip包-創(chuàng)新互聯(lián)

這篇文章主要為大家展示了“Android如何實(shí)現(xiàn)不解壓直接讀取zip包”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Android如何實(shí)現(xiàn)不解壓直接讀取zip包”這篇文章吧。

創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)與策劃設(shè)計(jì),華寧網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:華寧等地區(qū)。華寧做網(wǎng)站價(jià)格咨詢:028-86922220

文本:

zip包目錄結(jié)構(gòu):res/txt/data.json

文件sd卡路徑:android.os.Environment.getExternalStorageDirectory() + “/res.zip”

public static String readDataFile(String file) throws Exception {
  //截取路徑的文件名 res
  String fileName = file.substring(file.length() - 9, file.length() - 4);
  ZipFile zf = new ZipFile(file);
  InputStream in = new BufferedInputStream(new FileInputStream(file));
  ZipInputStream zin = new ZipInputStream(in);
  ZipEntry ze;
  while ((ze = zin.getNextEntry()) != null) {
   if (ze.isDirectory()) {
    //Do nothing
   } else {
    if (ze.getName().equals(fileName + "/txt/data.json")) {
     BufferedReader br = new BufferedReader(
       new InputStreamReader(zf.getInputStream(ze)));
     String line;
     while ((line = br.readLine()) != null) {
      return line;
     }
     br.close();
    }
   }
  }
  zin.closeEntry();
  return "";
 }

上面方法比較簡(jiǎn)單沒(méi)什么好說(shuō)的,大家理解就行,有點(diǎn)需要注意的就是在判斷是否是想要讀取的文件的時(shí)候,這里的路徑是以zip的壓縮目錄為根目錄做比較。也就是if (ze.getName().equals(fileName + "/txt/data.json")) 這句話中的fileName 當(dāng)前值為res。最后返回讀取的內(nèi)容String就完事了。

圖片和xml文件的讀取都差不多,下面直接貼出代碼了。

圖片:

zip包目錄結(jié)構(gòu):res/pic/haha.png

文件sd卡路徑:android.os.Environment.getExternalStorageDirectory() + “/res.zip”

public static Bitmap readGuidePic(String file, String ResId) throws Exception {
  String fileName = file.substring(file.length() - 9, file.length() - 4);
  ZipFile zf = new ZipFile(file);
  InputStream in = new BufferedInputStream(new FileInputStream(file));
  ZipInputStream zin = new ZipInputStream(in);
  ZipEntry ze;
  while ((ze = zin.getNextEntry()) != null) {
   if (ze.isDirectory()) {
    //Do nothing
   } else {
    Log.i("tag", "file - " + ze.getName() + " : " + ze.getSize() + " bytes");
    if (ze.getName().equals(fileName + "/pic/haha.png")) {
     InputStream is = zf.getInputStream(ze);
     Bitmap bitmap = BitmapFactory.decodeStream(is);
     return bitmap;
    }
   }
  }
  zin.closeEntry();
  return null;
 }

xml文件:

zip包目錄結(jié)構(gòu):res/xml/app.xml

文件sd卡路徑:android.os.Environment.getExternalStorageDirectory() + “/res.zip”

public static InputStream readAppFile(String file) throws IOException {
  String fileName = file.substring(file.length() - 9, file.length() - 4);
  ZipFile zf = new ZipFile(file);
  InputStream in = new BufferedInputStream(new FileInputStream(file));
  ZipInputStream zin = new ZipInputStream(in);
  ZipEntry ze;
  while ((ze = zin.getNextEntry()) != null) {
   if (ze.isDirectory()) {
    //Do nothing
   } else {
    if (ze.getName().equals(fileName + "/xml/app.xml")) {
     InputStream inputStream = zf.getInputStream(ze);
     return inputStream;
    }
   }
  }
  zin.closeEntry();
  return null;
 }

以上是“Android如何實(shí)現(xiàn)不解壓直接讀取zip包”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!


本文題目:Android如何實(shí)現(xiàn)不解壓直接讀取zip包-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://fisionsoft.com.cn/article/dhggds.html