-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRarUtil.java
More file actions
43 lines (38 loc) · 1.21 KB
/
RarUtil.java
File metadata and controls
43 lines (38 loc) · 1.21 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
package com.java;
import java.io.File;
import java.io.FileOutputStream;
import de.innosystec.unrar.Archive;
import de.innosystec.unrar.rarfile.FileHeader;
public class RarUtil {
/**
* 描述:支持rar解压
* @param args
*/
public static void main(String[] args) {
String filename = "C:/Users/hasee/Desktop/4444.rar";
File f = new File(filename);
Archive a = null;
try{
a = new Archive(f, "1234", false); //extract mode
}catch(Exception e){
e.printStackTrace();
}
if(a!=null){
a.getMainHeader().print();
FileHeader fh = a.nextFileHeader();
while (fh != null) {
try {
File out = new File("C:/Users/hasee/Desktop/aa/"
+ fh.getFileNameString().trim());
System.out.println(out.getAbsolutePath());
FileOutputStream os = new FileOutputStream(out);
a.extractFile(fh, os);
os.close();
} catch (Exception e) {
e.printStackTrace();
}
fh = a.nextFileHeader();
}
}
}
}