导航:首页 > 文件处理 > gunzip解压

gunzip解压

发布时间:2022-01-23 08:23:33

‘壹’ linux怎样解压gz文件

单纯的.gz文件解压,这种文件不可以使用tar命令解压,需要用gunzip解压,使用命令gzip

解压:gzip -b pythontab.gz

但是注意:gzip貌似不能够设置解压到指定目录,只能解压到当前目录。

解压单纯的.gz文件方法二:

使用zcat命令,然后把标准输出保存到文件即可。

‘贰’ gunzip可以直接在内存中解压缩数据吗

可以的
你可以自己写接口
也可以把解压目标放在虚盘上(tmpfs)

‘叁’ 急!如何解压rar.gzip格式的文件,谢谢!

只有解压RAR和ZIP的,没有gzip的。用RAR可以解压RAR和ZIP。gzip估计就别人改了后置名的,正常的只有zip的

‘肆’ 如何解压.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命令gzip -d怎么解压到指定路径

gzip 本身并没有解压到指定目录的参数。

如果是单文件压缩,可以用-c加输出重定向实现指定解压目录,如:

echohello>xxxx#创建一个文件
mkdirdir1#创建一个测试目录
gzip-cxxxx>./dir1/xxxx.gz
rmxxxx
cddir1
gzip-cdxxxx.gz>../xxxx
ls-lxxxx

如果是用tar命令打包的文件压缩包,可以直接用tar命令-C功能指定目录,如:

tarcvfxxx.tarxxxx#文件打包
gzipxxx.tar#压缩
tarzxvfxxx.tar.gz-C./dir1#解压到指定目录
ls-l./dir1/xxxx#查看结果

‘陆’ 压缩文件zip怎么解压

zip是一种常见的压缩文件,可以利用WINRAR程序将其打开。
具体操作方法:

1、上网搜索并下载应用程序“WINRAR”。下载完成后直接进行安装,其安装过程很简单。

2、安装完成后,在需要打开的zip文件上右击,从弹出的菜单中选择以“打开方式”。

3、在弹出的“打开方式”窗口中选择“WINRAR压缩文件管理器",然后点击“确定"按钮。

4、然后就会发现zip文件可以被打开啦。

5、接着选择要操作的文件或文件夹,点击主界面中的”解压缩“按钮,在弹出的窗口中选择要保存的文件路径即可。

6、还可以直接在需要打开的压缩文件上右击,从弹出的菜单中选择“WINRAR”→“解压到feifeidown\”。则会自动创建一个名称与压缩文件名相同的文件夹。

‘柒’ .rar.gzip文件怎么解压

先解压gzip再看rar是扩展名还是文件名,是扩展名再解压

‘捌’ 求后缀gzip的文件怎么打开或解压。

你可以下载一个7-zip 这是一个解压文件~~!下完后,在点文件文件时,他会出现。点open....在点击蹦出来的文件,就行了!

‘玖’ Linux解压.gz的命令

阅读全文

与gunzip解压相关的资料

热点内容
c单链表算法逆置 浏览:399
上哪里找地推APP软件 浏览:431
笑迎中考缓解压力读后感 浏览:276
阿里巴巴网易程序员买年金保险 浏览:189
空气压缩机曝氧 浏览:834
安卓自动重启怎么解决 浏览:504
python如何引入文件 浏览:811
ftp只能传输一个文件夹 浏览:835
php数组转换为json 浏览:815
手机10g压缩包 浏览:186
程序员和阎王爷 浏览:365
2021最新称骨法五两四算法 浏览:386
英语动词pdf 浏览:925
怎么看服务器组了什么阵列 浏览:981
为什么玩不了旧安卓游戏 浏览:698
app干什么用啊 浏览:508
为什么有的app没有反应 浏览:335
小米系统怎么样转安卓系统 浏览:564
视频pdf格式 浏览:158
php判断复选框是否选中 浏览:723