数据压缩
压缩类
功能
使用 GZIP 进行简单压缩
public class GZIPcompress {
public static void main(String[] args) {
if(args.length == 0) {
System.out.println("""
Usage:\s
GZIPcompress file
\tUses GZIP compression to compress the file to test.gz""");
System.exit(1);
}
try(InputStream in = new BufferedInputStream(
new FileInputStream(args[0]));
BufferedOutputStream out = new BufferedOutputStream(
new GZIPOutputStream(
new FileOutputStream("test/test.gz")))
) {
System.out.println("Writing File");
int c;
while ((c = in.read()) != -1)
out.write(c);
}catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("Reading File");
try(BufferedReader in2 = new BufferedReader(
new InputStreamReader(new GZIPInputStream(
new FileInputStream("test/test.gz"))))) {
in2.lines().forEach(System.out::println);
}catch (IOException e) {
throw new RuntimeException(e);
}
}
}使用 Zip 进行多文件存储
Java 档案(Jars)
字母
效果