1 /**
2 * 解压压缩包
3 *
4 * @param zipFile
5 * @param destFile
6 * @throws Exception
7 */
8 protected List<String> unTar(String tarFile, String destDir) throws Exception
9 {
10
11 List<String> retFiles = new ArrayList<>();
12 InputStream inputstream = null;
13 OutputStream outputstream = null;
14 TarInputStream zis = null;
15 File file = null;
16 try {
17 file = new File(tarFile);
18 inputstream = new FileInputStream(file);
19 zis = new TarInputStream(inputstream);
20 TarEntry tarEntry;
21 while ((tarEntry = zis.getNextEntry()) != null) {
22 retFiles.add(tarEntry.getName()); //添加解压缩之后的文件名,类的头目
23 File tempFile = new File(destDir + tarEntry.getName());
24 tempFile.createNewFile();
25 outputstream = new FileOutputStream(tempFile);
26 byte[] buf = new byte[1024*50];
27 int readsize = zis.read(buf, 0, buf.length);
28 while (readsize != -1) {
29 outputstream.write(buf, 0, readsize);
30 readsize = zis.read(buf, 0, buf.length);
31 }
32 outputstream.flush();
33 outputstream.close();
34 }
35 } catch (Exception e) {
36 log.error("error:", e);
37 throw e;
38 } finally {
39 if (null != outputstream) {
40 outputstream.flush();
41 }
42 if (null != inputstream) {
43 inputstream.close();
44 }
45 if (null != zis) {
46 zis.close();
47 }
48 if (null != outputstream) {
49 outputstream.close();
50 }
51 if (null != file) {
52 file.delete();
53 }
54 }
55 return retFiles;
56
57 }