依赖加测试main
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.24.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
<version>1.6</version>
</dependency>
public static void main(String[] args) throws Exception{
String archiveFileName = "E:/hebing2/example/example.7z";
String sourceFileName = "E:/hebing2/example/ts.fastq";
SevenZOutputFile outputFile = new SevenZOutputFile(new File(archiveFileName));
File fileToAdd = new File(sourceFileName);
SevenZArchiveEntry entry = outputFile.createArchiveEntry(fileToAdd, "ts1.fastq");
outputFile.putArchiveEntry(entry);
// 写入文件内容
byte[] content = Files.readAllBytes(fileToAdd.toPath());
outputFile.write(content);
outputFile.closeArchiveEntry();
outputFile.close();
System.out.println("压缩完成");
}