导航:首页 > 文件处理 > 多进程解压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文件相关的资料

热点内容
c编字符加密教程视频 浏览:109
安卓抖音直播怎么才能不对焦 浏览:867
公司介绍源码兼容手机 浏览:290
为什么页面会服务器异常 浏览:369
两个服务器磁盘阵列如何用 浏览:411
葫芦娃小y版不用解压的 浏览:904
我的世界服务器如何永久夜视 浏览:23
java获取http文件 浏览:966
linux系统数据恢复 浏览:500
王者荣耀算法技巧 浏览:939
命令与征服凯恩之怒打不开 浏览:193
多目标免疫优化算法 浏览:131
加密证券数字化 浏览:51
相册加密文件在哪里找到 浏览:19
抖音独立电商app是什么意思 浏览:808
公司晨会解压小游戏 浏览:340
怎么加密成摩斯密码 浏览:665
流体机械pdf 浏览:187
编译器管理的存储cache 浏览:182
自行车维修pdf 浏览:532