美文网首页
Android 不解压zip包读取里面的文件

Android 不解压zip包读取里面的文件

作者: 小相柳 | 来源:发表于2019-03-12 18:02 被阅读0次

    /**

    * 读取zip包里的文件(不需要解压zip)

    *

    * @param zipFile      zip包

    * @param readFileName 需要读取的文件名

    * @return 读取结果

    * @throws Exception

    */

    public static String readZipFile(File zipFile,String readFileName)throws Exception {

    ZipFile zf =new ZipFile(zipFile);

    InputStream in =new BufferedInputStream(new FileInputStream(zipFile));

    ZipInputStream zin =new ZipInputStream(in);

    ZipEntry ze;

    String mFileData ="";

    String line ="";

    while ((ze =zin.getNextEntry()) !=null) {

    if (!ze.isDirectory()) {

    RYLogUtils.d(TAG,"file - " +ze.getName());

    if (ze.getName().contains(readFileName)) {

    BufferedReader br =new BufferedReader(

    new InputStreamReader(zf.getInputStream(ze)));

    while ((line =br.readLine()) !=null) {

    RYLogUtils.d(TAG,line);

    mFileData =line;

    }

    br.close();

    }

    }

    }

    zin.closeEntry();

    in.close();

    return mFileData;

    }

    相关文章

      网友评论

          本文标题:Android 不解压zip包读取里面的文件

          本文链接:https://www.haomeiwen.com/subject/ijonpqtx.html