-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZipCommendDemo.java
More file actions
55 lines (46 loc) · 1.77 KB
/
ZipCommendDemo.java
File metadata and controls
55 lines (46 loc) · 1.77 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
package com.example.compress.runtime;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static jdk.nashorn.internal.runtime.ScriptingFunctions.exec;
/**
* Created by guolei on 16-8-9.
* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
* | 没有神兽,风骚依旧! |
* | QQ:1120832563 |
* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
*/
public class ZipCommendDemo {
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("zip ./dir/zip/demo.zip ./1.txt ./2.txt");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(p.getInputStream(),"utf-8"));
String s ;
while ((s=bufferedReader.readLine()) != null){
System.err.println(s);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static void uncompress(Runtime runtime){
try {
Process p = runtime.exec("unzip ./dir/zip/demo.zip -d ./dir/unzip/");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(p.getInputStream(),"utf-8"));
String s ;
while ((s=bufferedReader.readLine()) != null){
System.err.println(s);
}
} catch (Exception e){
e.printStackTrace();
}
}
}