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

/**

* 读取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;

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容