昨天用Java读取zip包,心寒,好久没接触Java读写文件了。恩,是到捡回的时候了。
step 1:读取zip包中的文件
ZipFile zipFile = new ZipFile(zipFileName); ZipEntry dataXML = zipFile.getEntry(fileName); InputStream input = zipFile.getInputStream(dataXML);
step 2:处理字符流(将InputSteam转换成String)
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); try { int i = 0; while((i = in.read()) != -1){ byteOut.write(i); } } catch (IOException e) { e.printStackTrace(); } return byteOut.toString();
step 3:知识点
InputStream.jpg
OutputSteam.jpg
Reader.jpg
Writer.jpg