導航:首頁 > 文件處理 > 多進程解壓gz文件

多進程解壓gz文件

發布時間:2022-04-20 12:39:31

① 如何解壓縮.gz文件

public static void makeZip(List<File> fileList,String zipPath,boolean isDelete) {
byte[] buf = new byte[1024];
try {
// Create the ZIP file
File zipFile = new File(zipPath);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
// Compress the files
for (int i = 0; i < fileList.size(); i++) {
FileInputStream in = new FileInputStream(fileList.get(i));
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(fileList.get(i).getName()));
// Transfer bytes from the file to the ZIP file
int len;
while ( (len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
System.out.println("壓縮完成.");

//把舊的文件刪除
if(isDelete == true){
for (int i = 0; i < fileList.size(); i++) {
File oldFile = fileList.get(i);
oldFile.delete();
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
File in1=new File("D:\\a.txt");
File in2=new File("D:\\b.txt");
File[] file=new File[]{in1,in2};
File zip=new File("D:\\ab.zip");
IDMZip mgr=new IDMZip();
mgr.ZipFiles(file, zip);
}

這個方法不管你是在windows下還是在linux下,都能正常執行。
追問
謝謝,但是我是要解壓這樣20140718_185819.data.tar.gz 不是zip的

回答
你可以試試。還有這個方法。都是我項目里曾經用到過的。都是可用的。
public static List unZip(String path) throws FileNotFoundException,
IOException {
path = path.replaceAll("\\\\","/");
String zipPath = path.substring(0,path.lastIndexOf("/")+1);
List xmlFileNameList = new ArrayList();
byte[] data = new byte[1024*2];
FileInputStream fis = new FileInputStream(path);
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry entry = null;
while((entry = zis.getNextEntry())!= null){
if(entry.isDirectory()){
File file = new File(zipPath+entry.getName());
file.mkdirs();
continue;
}

② 求助windows下面解壓gz的命令

tar.gz 是linux和unix下面比較常用的格式,幾個命令就可以把文件壓縮打包成tar.gz格式然而這種格式在windows並不多見,WinRAR、WinZip等主流壓縮工具可以釋放解開,卻不能打包生成。但是tar.gz在linux伺服器端很常用,於是許多習慣用Windows的Web開發人員,可能會遇到這個壓縮格式的麻煩。如何在windows系統生成tar.gz壓縮包,在網上搜了一下除了復雜的命令行和開源軟體之外,似乎沒有其他的。偶然發現「7-ZIP」這個軟體可以很方便地解決這個問題。具體步驟如下:一、下載7-ZIP,安裝後直接在你想要打包的文件上點右鍵菜單,會有一個7-ZIP的子菜單欄,類似WinRAR和WinZIP的那種右鍵菜單。然後選「7-ZIP」->「添加到壓縮檔案」,在彈出來的窗口裡有個「壓縮格式」的選項,裡面並沒有tar.gz格式,沒關系,裡面有一個Tar格式,第一步就是要先壓成tar格式。二、成功打包為Tar文件後,你可能會發現這個tar文件包和原來的文件大小一樣,也就是說tar本身並沒有壓縮,而是僅僅把它們打包成一個單獨的Tar文件。所以需要做第二步,再在這個tar文件上面點右鍵,選「7-ZIP」->「添加到壓縮檔案」,這時候彈出的窗口裡再看「壓縮格式選項」,發現多了兩個剛才沒有的,其中就包括「gzip」,是的,這一步就是把tar文件繼續壓縮成gzip。選擇「GZip」格式後確定,最後結果就是一個新的tar.gz格式的文件。經本人測試,兼容各種軟體,上傳到伺服器上也沒有問題。整個過程滑鼠流,完全不用敲什麼命令行。壓縮後的文件格式和大小如下:至此,在windows下面得到tar.gz完成!說明:安裝完了7-Zip 9.20 後,直接就可以選擇gzip格式壓縮成gz格式,無需中間的tar格式,

③ linux怎樣解壓gz文件

單純的.gz文件解壓,這種文件不可以使用tar命令解壓,需要用gunzip解壓,使用命令gzip

解壓:gzip -b pythontab.gz

但是注意:gzip貌似不能夠設置解壓到指定目錄,只能解壓到當前目錄。

解壓單純的.gz文件方法二:

使用zcat命令,然後把標准輸出保存到文件即可。

④ Linux解壓.gz的命令

⑤ 如何解壓gz文件

當在備份重要文件和通過網路發送大文件的時候,對文件進行壓縮非常有用。請注意,壓縮一個已經壓縮過的文件會增加額外開銷,因此你將會得到一個更大一些的文件。所以,請不要壓縮已經壓縮過的文件。在 GNU/Linux 中,有許多程序可以用來壓縮和解壓縮文件。在這篇教程中,我們僅學習其中兩個應用程序。

在類 Unix 系統中,最常見的用來壓縮文件的程序是:

⑥ 如何解壓.tar.gz gzip gz 類型文檔

java解壓縮.gz .zip .tar.gz等格式的壓縮包方法總結
1、.gz文件是linux下常見的壓縮格式。使用 java.util.zip.GZIPInputStream即可,壓縮是 java.util.zip.GZIPOutputStream

1 public static void unGzipFile(String sourcedir) {
2 String ouputfile = "";
3 try {
4 //建立gzip壓縮文件輸入流
5 FileInputStream fin = new FileInputStream(sourcedir);
6 //建立gzip解壓工作流
7 GZIPInputStream gzin = new GZIPInputStream(fin);
8 //建立解壓文件輸出流
9 ouputfile = sourcedir.substring(0,sourcedir.lastIndexOf('.'));
10 ouputfile = ouputfile.substring(0,ouputfile.lastIndexOf('.'));
11 FileOutputStream fout = new FileOutputStream(ouputfile);
12
13 int num;
14 byte[] buf=new byte[1024];
15
16 while ((num = gzin.read(buf,0,buf.length)) != -1)
17 {
18 fout.write(buf,0,num);
19 }
20
21 gzin.close();
22 fout.close();
23 fin.close();
24 } catch (Exception ex){
25 System.err.println(ex.toString());
26 }
27 return;
28 }

2、zip文件,使用java.util.zip.ZipEntry 和 java.util.zip.ZipFile

1 /**
2 * 解壓縮zipFile
3 * @param file 要解壓的zip文件對象
4 * @param outputDir 要解壓到某個指定的目錄下
5 * @throws IOException
6 */
7 public static void unZip(File file,String outputDir) throws IOException {
8 ZipFile zipFile = null;
9
10 try {
11 Charset CP866 = Charset.forName("CP866"); //specifying alternative (non UTF-8) charset
12 //ZipFile zipFile = new ZipFile(zipArchive, CP866);
13 zipFile = new ZipFile(file, CP866);
14 createDirectory(outputDir,null);//創建輸出目錄
15
16 Enumeration<?> enums = zipFile.entries();
17 while(enums.hasMoreElements()){
18
19 ZipEntry entry = (ZipEntry) enums.nextElement();
20 System.out.println("解壓." + entry.getName());
21
22 if(entry.isDirectory()){//是目錄
23 createDirectory(outputDir,entry.getName());//創建空目錄
24 }else{//是文件
25 File tmpFile = new File(outputDir + "/" + entry.getName());
26 createDirectory(tmpFile.getParent() + "/",null);//創建輸出目錄
27
28 InputStream in = null;
29 OutputStream out = null;
30 try{
31 in = zipFile.getInputStream(entry);;
32 out = new FileOutputStream(tmpFile);
33 int length = 0;
34
35 byte[] b = new byte[2048];
36 while((length = in.read(b)) != -1){
37 out.write(b, 0, length);
38 }
39
40 }catch(IOException ex){
41 throw ex;
42 }finally{
43 if(in!=null)
44 in.close();
45 if(out!=null)
46 out.close();
47 }
48 }
49 }
50
51 } catch (IOException e) {
52 throw new IOException("解壓縮文件出現異常",e);
53 } finally{
54 try{
55 if(zipFile != null){
56 zipFile.close();
57 }
58 }catch(IOException ex){
59 throw new IOException("關閉zipFile出現異常",ex);
60 }
61 }
62 }
63
64 /**
65 * 構建目錄
66 * @param outputDir
67 * @param subDir
68 */
69 public static void createDirectory(String outputDir,String subDir){
70 File file = new File(outputDir);
71 if(!(subDir == null || subDir.trim().equals(""))){//子目錄不為空
72 file = new File(outputDir + "/" + subDir);
73 }
74 if(!file.exists()){
75 if(!file.getParentFile().exists())
76 file.getParentFile().mkdirs();
77 file.mkdirs();
78 }
79 }

3、.tar.gz文件可以看做先用tar打包,再使用gz進行壓縮。
使用org.apache.tools.tar.TarEntry; org.apache.tools.tar.TarInputStream 和 org.apache.tools.tar.TarOutputStream

1 //------------------------------------------------------------------------------------------------------
2 /**
3 * 解壓tar.gz 文件
4 * @param file 要解壓的tar.gz文件對象
5 * @param outputDir 要解壓到某個指定的目錄下
6 * @throws IOException
7 */
8 public static void unTarGz(File file,String outputDir) throws IOException{
9 TarInputStream tarIn = null;
10 try{
11 tarIn = new TarInputStream(new GZIPInputStream(
12 new BufferedInputStream(new FileInputStream(file))),
13 1024 * 2);
14
15 createDirectory(outputDir,null);//創建輸出目錄
16
17 TarEntry entry = null;
18 while( (entry = tarIn.getNextEntry()) != null ){
19
20 if(entry.isDirectory()){//是目錄
21 entry.getName();
22 createDirectory(outputDir,entry.getName());//創建空目錄
23 }else{//是文件
24 File tmpFile = new File(outputDir + "/" + entry.getName());
25 createDirectory(tmpFile.getParent() + "/",null);//創建輸出目錄
26 OutputStream out = null;
27 try{
28 out = new FileOutputStream(tmpFile);
29 int length = 0;
30
31 byte[] b = new byte[2048];
32
33 while((length = tarIn.read(b)) != -1){
34 out.write(b, 0, length);
35 }
36
37 }catch(IOException ex){
38 throw ex;
39 }finally{
40
41 if(out!=null)
42 out.close();
43 }
44 }
45 }
46 }catch(IOException ex){
47 throw new IOException("解壓歸檔文件出現異常",ex);
48 } finally{
49 try{
50 if(tarIn != null){
51 tarIn.close();
52 }
53 }catch(IOException ex){
54 throw new IOException("關閉tarFile出現異常",ex);
55 }
56 }
57 }

使用到的包頭有:

1 import java.io.BufferedInputStream;
2 import java.io.File;
3 import java.io.FileInputStream;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8
9 import java.nio.charset.Charset;
10 import java.util.Enumeration;
11 import java.util.zip.GZIPInputStream;
12 import java.util.zip.ZipEntry;
13 import java.util.zip.ZipFile;
14
15 import org.apache.tools.tar.TarEntry;
16 import org.apache.tools.tar.TarInputStream;
17 import org.apache.tools.tar.TarOutputStream;

⑦ Linux下如何解壓文件夾下所有.gz的文件

需要准備的材料分別是:電腦、linux連接工具。

1、首先連接上linux主機,進入等待輸入指令的linux命令行狀態。

⑧ gz後綴怎麼解壓

1、在Windows系統環境下,安裝解壓軟體

閱讀全文

與多進程解壓gz文件相關的資料

熱點內容
pdf轉midi 瀏覽:920
c程序編譯答案 瀏覽:952
java五子棋網路 瀏覽:170
解壓源碼命令 瀏覽:989
linux原理簡述 瀏覽:368
手機app怎麼在桌面自己就沒了 瀏覽:493
超高分伺服器干什麼用的 瀏覽:83
怎麼把自己的伺服器備份成另一個 瀏覽:116
javafloat類型 瀏覽:401
instagram安卓無網路怎麼弄 瀏覽:704
php彈出窗口調用另外一個html 瀏覽:432
程序員不幸福調查 瀏覽:843
蘇寧程序員待遇 瀏覽:552
excel如何設置區域網伺服器 瀏覽:902
linux查看tomcat命令 瀏覽:209
國外便宜雲伺服器 瀏覽:853
程序員歲數大了 瀏覽:794
廣州程序員女朋友學醫 瀏覽:877
linux怎麼復制命令行 瀏覽:345
一氧化碳單片機報警 瀏覽:953