欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

壓縮文件代碼java 壓縮文件代碼怎么用

關于Java的解壓縮的代碼?

package?com.javatest.techzero.gui;??

成都創(chuàng)新互聯(lián)公司是一家網站設計公司,集創(chuàng)意、互聯(lián)網應用、軟件技術為一體的創(chuàng)意網站建設服務商,主營產品:響應式網站設計品牌網站制作全網營銷推廣。我們專注企業(yè)品牌在網站中的整體樹立,網絡互動的體驗,以及在手機等移動端的優(yōu)質呈現(xiàn)。成都網站制作、成都網站建設、移動互聯(lián)產品、網絡運營、VI設計、云產品.運維為核心業(yè)務。為用戶提供一站式解決方案,我們深知市場的競爭激烈,認真對待每位客戶,為客戶提供賞析悅目的作品,網站的價值服務。

import?java.io.File;

import?java.io.FileInputStream;

import?java.io.FileOutputStream;

import?java.io.InputStream;

import?java.io.OutputStream;

import?java.util.zip.ZipEntry;

import?java.util.zip.ZipFile;

import?java.util.zip.ZipInputStream;?

public?class?ZipFileDemo?{

@SuppressWarnings("resource")

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

File?file?=?new?File("d:"?+?File.separator?+?"test.zip");

File?outFile?=?null;

ZipFile?zipFile?=?new?ZipFile(file);

ZipInputStream?zipInput?=?new?ZipInputStream(new?FileInputStream(file));

ZipEntry?entry?=?null;

InputStream?input?=?null;

OutputStream?out?=?null;

while?((entry?=?zipInput.getNextEntry())?!=?null)?{

System.out.println("開始解壓縮"?+?entry.getName()?+?"文件。。。");

outFile?=?new?File("d:"?+?File.separator?+?entry.getName());

if?(!outFile.getParentFile().exists())?{

outFile.getParentFile().mkdir();

}

if?(!outFile.exists())?{

outFile.createNewFile();

}

input?=?zipFile.getInputStream(entry);

out?=?new?FileOutputStream(outFile);

int?temp?=?0;

while?((temp?=?input.read())?!=?-1)?{

SPAN?style="WHITE-SPACE:?pre"?/SPAN//System.out.println(temp);

out.write(temp);

}

input.close();

out.close();

}

System.out.println("Done!");

}

}

僅供參考

如何使用JAVA代碼壓縮PDF文件

用java代碼壓縮應用到程序了,代碼一般是比較復雜的,對pdf文件的mate標簽優(yōu)化,這類標簽包括三類,pdf文件不是網頁就是個文件,何況我們可以用pdf壓縮工具壓縮,下面有個解決方法,樓主可以做參照。

1:點擊打開工具,打開主頁面上有三個功能進行選擇,我們選擇pdf文件壓縮。

2:這這個頁面中我們選擇pdf文件在這里打開,點擊“添加文件”按鈕將文件添加進來。

3:然后在頁面中點擊“開始壓縮”就可以開始壓縮文件了。

4:壓縮完成的文件頁面會顯示已經完成。

如何使用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

將壓縮文件解壓到指定的文件夾中。代碼壓縮文件去拖進java將壓縮文件解壓到指定的文件夾中。Java是由SunMicrosystems公司于1995年5月推出的Java面向對象程序設計語言和Java平臺的總稱。

當前名稱:壓縮文件代碼java 壓縮文件代碼怎么用
網站網址:http://chinadenli.net/article10/hppodo.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供網頁設計公司營銷型網站建設定制開發(fā)網站收錄網站維護網站設計

廣告

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

外貿網站制作