-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGzipCommendDemo.java
More file actions
62 lines (53 loc) · 1.89 KB
/
GzipCommendDemo.java
File metadata and controls
62 lines (53 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.example.compress.runtime;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import static javafx.scene.input.KeyCode.F;
/**
* Created by guolei on 16-8-10.
* ????????????????????????????????????
* | ?????????? |
* | QQ:1120832563 |
* ????????????????????????????????????
*/
public class GzipCommendDemo {
public static void main(String[] args){
String systemType = System.getProperty("os.name");
Runtime runtime = Runtime.getRuntime();
// compress(runtime);
uncompress(runtime);
}
private static void compress(Runtime runtime){
try {
Process p = runtime.exec("gzip 3.txt");
// p.waitFor();
// int value = p.exitValue();
// System.err.println("this is result-->" + value);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(p.getInputStream(),"utf-8"));
String s ;
while ((s=bufferedReader.readLine()) != null){
// new FileOutputStream(new File("./3.txt")).write(s.getBytes("utf-8"));
System.err.println(s);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
private static void uncompress(Runtime runtime){
try {
Process p = runtime.exec("gunzip 3.txt.gz");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(p.getErrorStream(),"utf-8"));
String s ;
while ((s=bufferedReader.readLine()) != null){
new FileOutputStream(new File("./3.txt")).write(s.getBytes("utf-8"));
}
} catch (Exception e){
e.printStackTrace();
}
}
}