99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

java壓縮文件gz代碼 java解壓gz

java程序如何批量解壓GZIP壓縮包

給你一段單個文件解壓gzip文件代碼

10年積累的成都做網(wǎng)站、網(wǎng)站建設經(jīng)驗,可以快速應對客戶對網(wǎng)站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡服務。我雖然不認識你,你也不認識我。但先做網(wǎng)站后付款的網(wǎng)站建設流程,更有河源免費網(wǎng)站建設讓你可以放心的選擇與我們合作。

批量解壓的話 File f = new File("要解壓的文件夾目錄");

String paths[] = f.list(); // 取得文件夾下的文件

然后循環(huán)調(diào)用下面的方法就可以了。

try {

// Open the compressed file

String inFilename = "infile.gzip";

GZIPInputStream in = new GZIPInputStream(new FileInputStream(inFilename));

// Open the output file

String outFilename = "outfile";

OutputStream out = new FileOutputStream(outFilename);

// Transfer bytes from the compressed file to the output file

byte[] buf = new byte[1024];

int len;

while ((len = in.read(buf)) 0) {

out.write(buf, 0, len);

}

// Close the file and stream

in.close();

out.close();

} catch (IOException e) {

}

java如何壓縮成gz包

import java.io.*;

import java.util.zip.*;

public class GZIPcompress {

public static void main(String[] args) {

try {

BufferedReader in =

new BufferedReader(

new FileReader(args[0]));

BufferedOutputStream out =

new BufferedOutputStream(

new GZIPOutputStream(

new FileOutputStream("test.gz")));

System.out.println("Writing file");

int c;

while((c = in.read()) != -1)

out.write(c);

in.close();

out.close();

System.out.println("Reading file");

BufferedReader in2 =

new BufferedReader(

new InputStreamReader(

new GZIPInputStream(

new FileInputStream("test.gz"))));

String s;

while((s = in2.readLine()) != null)

System.out.println(s);

} catch(Exception e) {

e.printStackTrace();

}

}

} ///:~

java里怎么解壓tar.gz文件啊,網(wǎng)上好多例子都不行

最后怎么解決的,我現(xiàn)在也遇到這個問題了,單個文件可以解壓可以壓縮,寫入的測試內(nèi)容也在,換成文件夾就不行了。能找到的案例全都是解壓成文件,但是本身是個文件夾的GZ包解壓了以后也打不開。

java調(diào)用linux命令解壓gz

1.

將文件壓縮為 .gz 格式,只能壓縮文件:gzip ①、命令名稱:gzip ②、英文原意:GNU zip ③、命令所在路徑:/bin/gzip ④、執(zhí)行權限:所有用戶 ...

2.

將 .gz 文件解壓:gunzip

命令名稱:gunzip

如何使用java壓縮文件夾成為zip包

在JDK中有一個zip工具類:

java.util.zip ? ?Provides classes for reading and writing the standard ZIP and

GZIP file formats.

使用此類可以將文件夾或者多個文件進行打包壓縮操作。

在使用之前先了解關鍵方法:

ZipEntry(String name) ????????Creates a new zip entry with the specified name.

使用ZipEntry的構造方法可以創(chuàng)建一個zip壓縮文件包的實例,然后通過ZipOutputStream將待壓縮的文件以流的形式寫進該壓縮包中。具體實現(xiàn)代碼如下:

import?java.io.BufferedInputStream;??

import?java.io.BufferedOutputStream;??

import?java.io.File;??

import?java.io.FileInputStream;??

import?java.io.FileNotFoundException;??

import?java.io.FileOutputStream;??

import?java.io.IOException;??

import?java.util.zip.ZipEntry;??

import?java.util.zip.ZipOutputStream;??

/**?

*?將文件夾下面的文件?

*?打包成zip壓縮文件?

*??

*?@author?admin?

*?

*/??

public?final?class?FileToZip?{??

private?FileToZip(){}??

/**?

*?將存放在sourceFilePath目錄下的源文件,打包成fileName名稱的zip文件,并存放到zipFilePath路徑下?

*?@param?sourceFilePath?:待壓縮的文件路徑?

*?@param?zipFilePath?:壓縮后存放路徑?

*?@param?fileName?:壓縮后文件的名稱?

*?@return?

*/??

public?static?boolean?fileToZip(String?sourceFilePath,String?zipFilePath,String?fileName){??

boolean?flag?=?false;??

File?sourceFile?=?new?File(sourceFilePath);??

FileInputStream?fis?=?null;??

BufferedInputStream?bis?=?null;??

FileOutputStream?fos?=?null;??

ZipOutputStream?zos?=?null;??

if(sourceFile.exists()?==?false){??

System.out.println("待壓縮的文件目錄:"+sourceFilePath+"不存在.");??

}else{??

try?{??

File?zipFile?=?new?File(zipFilePath?+?"/"?+?fileName?+".zip");??

if(zipFile.exists()){??

System.out.println(zipFilePath?+?"目錄下存在名字為:"?+?fileName?+".zip"?+"打包文件.");??

}else{??

File[]?sourceFiles?=?sourceFile.listFiles();??

if(null?==?sourceFiles?||?sourceFiles.length1){??

System.out.println("待壓縮的文件目錄:"?+?sourceFilePath?+?"里面不存在文件,無需壓縮.");??

}else{??

fos?=?new?FileOutputStream(zipFile);??

zos?=?new?ZipOutputStream(new?BufferedOutputStream(fos));??

byte[]?bufs?=?new?byte[1024*10];??

for(int?i=0;isourceFiles.length;i++){??

//創(chuàng)建ZIP實體,并添加進壓縮包??

ZipEntry?zipEntry?=?new?ZipEntry(sourceFiles[i].getName());??

zos.putNextEntry(zipEntry);??

//讀取待壓縮的文件并寫進壓縮包里??

fis?=?new?FileInputStream(sourceFiles[i]);??

bis?=?new?BufferedInputStream(fis,?1024*10);??

int?read?=?0;??

while((read=bis.read(bufs,?0,?1024*10))?!=?-1){??

zos.write(bufs,0,read);??

}??

}??

flag?=?true;??

}??

}??

}?catch?(FileNotFoundException?e)?{??

e.printStackTrace();??

throw?new?RuntimeException(e);??

}?catch?(IOException?e)?{??

e.printStackTrace();??

throw?new?RuntimeException(e);??

}?finally{??

//關閉流??

try?{??

if(null?!=?bis)?bis.close();??

if(null?!=?zos)?zos.close();??

}?catch?(IOException?e)?{??

e.printStackTrace();??

throw?new?RuntimeException(e);??

}??

}??

}??

return?flag;??

}??

public?static?void?main(String[]?args){??

String?sourceFilePath?=?"D:\\TestFile";??

String?zipFilePath?=?"D:\\tmp";??

String?fileName?=?"12700153file";??

boolean?flag?=?FileToZip.fileToZip(sourceFilePath,?zipFilePath,?fileName);??

if(flag){??

System.out.println("文件打包成功!");??

}else{??

System.out.println("文件打包失敗!");??

}??

}??

}

當前名稱:java壓縮文件gz代碼 java解壓gz
當前路徑:http://www.yijiale78.com/article16/doddjdg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設計公司外貿(mào)網(wǎng)站建設微信小程序小程序開發(fā)Google網(wǎng)站維護

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名