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

2019-03-12  本文已影响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;

}

上一篇下一篇

猜你喜欢

热点阅读