如何在java中实现对zip和rar文件的解压
TIPS:本文共有 1100 个字,阅读大概需要 3 分钟。
java中有zip包,可以使用
public void getZipFiles(String zipFile, String destFolder) throws IOException { BufferedOutputStream dest = null ZipInputStream zis = new ZipInputStream( new BufferedInputStream( new FileInputStream(zipFile))) ZipEntry entry while (( entry = zis.getNextEntry() ) != null) { System.out.println( "Extracting: " + entry.getName() ) int count byte data[] = new byte[BUFFER] if (entry.isDirectory()) { new File( destFolder + "/" + entry.getName() ).mkdirs() continue } else { int di = entry.getName().lastIndexOf( '/' ) if (di != -1) {new File( destFolder + "/" + entry.getName() .substring( 0, di ) ).mkdirs() } } FileOutputStream fos = new FileOutputStream( destFolder + "/" + entry.getName() ) dest = new BufferedOutputStream( fos ) while (( count = zis.read( data ) ) != -1) dest.write( data, 0, count ) dest.flush() dest.close() }}
rar的只能用第三方api,比如junrar
https://github.com/edmund-wagner/junrar
如果觉得《如何在java中实现对zip和rar文件的解压》对你有帮助,请点赞、收藏,并留下你的观点哦!