解压缩方法
//解压 public void extractTarFile(String tarFilePath, String destDirPath) throws IOException { File tarFile = new File(tarFilePath); File destDir = new File(destDirPath); // 创建TarArchiveInputStream try (TarArchiveInputStream tarInput = new TarArchiveInputStream(new FileInputStream(tarFile))) { TarArchiveEntry entry; // 逐个读取条目并解压 while ((entry = tarInput.getNextTarEntry()) != null) { if (entry.isDirectory()) { // 如果是目录,创建相应的目录 File directory = new File(destDir, entry.getName()); directory.mkdirs(); } else { // 如果是文件,创建相应的文件并将数据写入 File outputFile = new File(destDir, entry.getName()); try (BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(outputFile))) { byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = tarInput.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); } } } } } }