導航:首頁 > 編程語言 > java壓縮數據

java壓縮數據

發布時間:2023-06-02 11:03:57

java中的壓縮原理是什麼

什麼是壓縮文件? 簡單的說,就是經過壓縮軟體壓縮的文件叫壓縮文件,壓縮的原理是把文件的二進制代碼壓縮,把相鄰的0,1代碼減少,比如有000000,可以把它變成6個0 的寫法60,來減少該文件的空間。 ■怎麼壓縮文件? 首先要安裝壓縮軟體,現在比較流行的是WinRAR「一種高效快速的文件壓縮軟體(中文版)」。 其次是建立一個壓縮包:選擇你要製作成壓縮包的文件或文件夾,當然你也可也多選,方法同資源管理器,也就是按住Ctrl或Shift再選擇文件(文件夾)。 選取完畢之後,就可以單擊工具欄上的「壓縮」按鈕,在這里你可以選擇壓縮格式:RAR和ZIP。 如果你想得到較大的壓縮率,建議選擇RAR格式。 各個選項選擇好以後,單擊確定按鈕就開始製作壓縮包了,非常方便。有時候大家會遇到這個問題,就是你在一個論壇里要上傳一些文件壓縮包,壓縮包大小有3M,但是論壇限制會員上傳大小隻有2M,怎麼辦呢? 其實辦法很簡單,就是在你壓縮這個文件時,分成幾個帶分卷壓縮包,分卷包大小設置為2M即可,比如:原來文件名為123.rar(3M),壓縮成分卷包後為123.part1.rar(2M)與123.part2.rar(1M)兩個文件,這樣你就可以上傳了。 具體方法如下: 1、在要壓縮的文件上點右鍵 2、添加到壓縮文件.... 3、選常規 4、壓縮方式選最好 5、批定壓縮分卷大小(按位元組計算),1M = 1024K,1K = 1024位元組,填寫數字即可 當你下載了帶有分卷的壓縮包後,如何解壓文件呢? 具體方法如下: 1、把所有的壓縮分卷全部下載完整 2、所有分卷必須在同一個文件夾內 3、然後雙擊解壓第一個分卷,即可 註:分卷解壓的文件必須是連續的,若分卷未下載完整,則解壓時自然會提示需要下一壓縮分卷

㈡ 用java如何實現壓縮字元串

package javase1.day02;
/**
* 1)一種字元串壓縮演算法
* str ="aaaabbccccddeaaa"
* 壓縮為:"4a2b4c2d1e3a"
* 原理實現:
* str = "aaaabbccccddeaaa"
*
* c = str.charAt(i)//c是每個字元
* 1) 初始化
* StringBuilder buf = new StringBuilder();
* int count = 0;代表相同的字元個數
* char ch = str.charAt(0);代表正在統計的相同字元'a'
* 2) 從i=1開始迭代每個字元
* c = str.charAt(i);//c是每個當前字元
* 3) 檢查當前字元c與被統計ch是否一致
* 如果一致 count++
* 否則(不一致)
* 向緩沖區buf增加count+ch
* count=0,ch=c;
* 3)沒有下個字元就結束
* 4)還有字元串嗎?回到2)
*
* 2)實現還原演算法
* str = "4a2b4c2d1e3a";
* i
*/
public class Demo5 {
public static void main(String[] args) {
String s = comp("aaaawwwwe");
System.out.println(s);
// System.out.println(decomp(s));

}
public static String comp(String str){
int i = 1;
StringBuilder buf = new StringBuilder();
int count = 1;
char ch = str.charAt(0);
for(;;){
char c = i==str.length() ? '\10':str.charAt(i);
if(c==ch){
count++;
}else{
if(count == 1)
buf.append(ch);
else
buf.append(count).append(ch);
count=1;
ch = c;
}
i++;
if(i==str.length()+1){
break;
}
}
return buf.toString();

}
}

㈢ JAVA 壓縮和序列化

壓縮和序列化主要用在數據的存儲和傳輸上,二者都是由IO流相關知識實現,這里統一介紹下。

全部章節傳送門:

Java I/O類支持讀寫壓縮格式的數據流,你可以用他們對其他的I/O流進行封裝,以提供壓縮功能。

GZIP介面比較簡單,適合對單個數據流進行壓縮,在Linux系統中使用較多。

ZIP格式可以壓縮多個文件,而且可以和壓縮工具進行協作,是經常使用的壓縮方法。

JAR(Java Archive,Java 歸檔文件)是與平台無關的文件格式,它允許將許多文件組合成一個壓縮文件。為 J2EE 應用程序創建的 JAR 文件是 EAR 文件(企業 JAR 文件)。

JAR 文件格式以流行的 ZIP 文件格式為基礎。與 ZIP 文件不同的是,JAR 文件不僅用於壓縮和發布,而且還用於部署和封裝庫、組件和插件程序,並可被像編譯器和 JVM 這樣的工具直接使用。在 JAR 中包含特殊的文件,如 manifests 和部署描述符,用來指示工具如何處理特定的 JAR。

如果一個Web應用程序的目錄和文件非常多,那麼將這個Web應用程序部署到另一台機器上,就不是很方便了,我們可以將Web應用程序打包成Web 歸檔(WAR)文件,這個過程和把Java類文件打包成JAR文件的過程類似。利用WAR文件,可以把Servlet類文件和相關的資源集中在一起進行發布。在這個過程中,Web應用程序就不是按照目錄層次結構來進行部署了,而是把WAR文件作為部署單元來使用。

一個WAR文件就是一個Web應用程序,建立WAR文件,就是把整個Web應用程序(不包括Web應用程序層次結構的根目錄)壓縮起來,指定一個.war擴展名。下面我們將第2章的Web應用程序打包成WAR文件,然後發布

要注意的是,雖然WAR文件和JAR文件的文件格式是一樣的,並且都是使用jar命令來創建,但就其應用來說,WAR文件和JAR文件是有根本區別的。JAR文件的目的是把類和相關的資源封裝到壓縮的歸檔文件中,而對於WAR文件來說,一個WAR文件代表了一個Web應用程序,它可以包含 Servlet、HTML頁面、Java類、圖像文件,以及組成Web應用程序的其他資源,而不僅僅是類的歸檔文件。

在命令行輸入jar即可查看jar命令的使用方法。

把對象轉換為位元組序列的過程稱為對象的序列化。把位元組序列恢復為對象的過程稱為對象的反序列化。

對象的序列化主要有兩種用途:

java.io.ObjectOutputStream代表對象輸出流,它的writeObject(Object obj)方法可對參數指定的obj對象進行序列化,把得到的位元組序列寫到一個目標輸出流中。

java.io.ObjectInputStream代表對象輸入流,它的readObject()方法從一個源輸入流中讀取位元組序列,再把它們反序列化為一個對象,並將其返回。

只有實現了Serializable的對象才能被序列化。對象序列化包括如下步驟:

對象反序列化的步驟如下:

創建一個可以可以序列化的對象。

然後進行序列化和反序列化測試。

s​e​r​i​a​l​V​e​r​s​i​o​n​U​I​D​:​ ​字​面​意​思​上​是​序​列​化​的​版​本​號​,凡是實現Serializable介面的類都有一個表示序列化版本標識符的靜態變數。

JAVA序列化的機制是通過判斷類的serialVersionUID來驗證的版本一致的。在進行反序列化時,JVM會把傳來的位元組流中的serialVersionUID於本地相應實體類的serialVersionUID進行比較。如果相同說明是一致的,可以進行反序列化,否則會出現反序列化版本一致的異常,即是InvalidCastException。

為了提高serialVersionUID的獨立性和確定性,強烈建議在一個可序列化類中顯示的定義serialVersionUID,為它賦予明確的值。

控制序列化欄位還可以使用Externalizable介面替代Serializable借口。此時需要定義一個默認構造器,否則將為得到一個異常(java.io.InvalidClassException: Person; Person; no valid constructor);還需要定義兩個方法(writeExternal()和readExternal())來控制要序列化的欄位。

如下為將Person類修改為使用Externalizable介面。

transient修飾符僅適用於變數,不適用於方法和類。在序列化時,如果我們不想序列化特定變數以滿足安全約束,那麼我們應該將該變數聲明為transient。執行序列化時,JVM會忽略transient變數的原始值並將默認值(引用類型就是null,數字就是0)保存到文件中。因此,transient意味著不要序列化。

靜態變數不是對象狀態的一部分,因此它不參與序列化。所以將靜態變數聲明為transient變數是沒有用處的。

㈣ java編程:數據壓縮規則

你是不是問如何編寫一個程序來壓縮數據?如果你是想解決這個問題的話,繼續往下看,如果你只是想要應付考試的話就算了。

—— 分割線

JDK本身提供了數據壓縮的一個API

java.util.zip.Deflater.deflateBytes(byte[] b, int off, int len)

以下是我使用的一個例子,有點多,注釋看不懂可以問我,不知道怎麼用可以問我,其他的就算了。

/**
* threshold value for compress
*/
public static final int THRESHOLD = 1200;

/**
* Answer a byte array compressed in the DEFLATER format from bytes.
*
* @param bytes
* a byte array
* @return byte[] compressed bytes
* @throws IOException
*/
public static byte[] compress(byte[] bytes)
{
// Create the compressor with highest level of compression
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);

// Give the compressor the data to compress
compressor.setInput(bytes);
compressor.finish();

// Create an expandable byte array to hold the compressed data.
// You cannot use an array that's the same size as the orginal because
// there is no guarantee that the compressed data will be smaller than
// the uncompressed data.
ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);

// Compress the data
byte[] buf = new byte[1024];
while (!compressor.finished())
{
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
try
{
bos.close();
}
catch (IOException e)
{
}

// Get the compressed data
byte[] compressedData = bos.toByteArray();
return compressedData;
}

/**
* Answer a byte array that has been decompressed from the DEFLATER format.
*
* @param bytes
* a byte array
* @return byte[] compressed bytes
* @throws IOException
*/
public static byte[] uncompress(byte[] bytes)
{
// Create the decompressor and give it the data to compress
Inflater decompressor = new Inflater();
decompressor.setInput(bytes);

// Create an expandable byte array to hold the decompressed data
ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);

// Decompress the data
byte[] buf = new byte[1024];
while (!decompressor.finished())
{
try
{
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
catch (DataFormatException e)
{
}
}
try
{
bos.close();
}
catch (IOException e)
{
}

// Get the decompressed data
byte[] decompressedData = bos.toByteArray();
return decompressedData;
}

㈤ Java壓縮與解壓縮問題

/**
*類名:zipFileRelease
*說明:一個zip文件解壓類
*介紹:主要的zip文件釋放方法releaseHandle()
* 用ZipInputStream類和ZipEntry類將zip文件的入口清單列舉出來,然後
* 根據用戶提供的輸出路徑和zip文件的入口進行組合通過DataOutputStream
* 和File類進行文件的創建和目錄的創建,創建文件時的文件數據是通過
* ZipInputStream類、ZipEntry類、InputStream類之間的套嵌組合獲得的。
*注意:如果zip文件中包含中文路徑程序將會拋出異常
*日期:2005-7-1
*作者:Pcera
*/

import java.io.*;
import java.util.*;
import java.util.zip.*;

class zipFileRelease{

private String inFilePath;
private String releaseFilePath;
private String[] FileNameArray; //存放文件名稱的數組
private ZipEntry entry;
//
private FileInputStream fileDataIn;
private FileOutputStream fileDataOut;
private ZipInputStream zipInFile;
private DataOutputStream writeData;
private DataInputStream readData;
//
private int zipFileCount = 0; //zip文件中的文件總數
private int zipPathCount = 0; //zip文件中的路徑總數

/**
*初始化函數
*初始化zip文件流、輸出文件流以及其他變數的初始化
*/
public zipFileRelease(String inpath,String releasepath){
inFilePath = inpath;
releaseFilePath = releasepath;
}

/**
*初始化讀取文件流函數
*參數:FileInputStream類
*返回值:初始化成功返回0,否則返回-1
*/
protected long initInStream(ZipInputStream zipFileA){
try{
readData = new DataInputStream(zipFileA);
return 0;
}catch(Exception e){
e.printStackTrace();
return -1;
}
}

/**
*測試文件路徑
*參數:zip文件的路徑和要釋放的位置
*返回值:是兩位整數,兩位數中的十位代表輸入路徑和輸出路徑(1輸入、2輸出)
* 各位數是代表絕對路徑還是相對路徑(1絕對、0相對)
* 返回-1表示路徑無效

protected long checkPath(String inPath,String outPath){
File infile = new File(inPath);
File infile = new File(outPath);

}
*/

/**
*初始化輸出文件流
*參數:File類
*返回值:初始化成功返回0,否則返回-1
*/
protected long initOutStream(String outFileA){
try{
fileDataOut = new FileOutputStream(outFileA);
writeData = new DataOutputStream(fileDataOut);
return 0;
}catch(IOException e){
e.printStackTrace();
return -1;
}
}

/**
*測試文件是否存在方法
*參數:File類
*返回值:如果文件存在返迴文件大小,否則返回-1
*/
public long checkFile(File inFileA){
if (inFileA.exists()){
return 0;
}else{
return -1;
}
}

/**
*判斷文件是否可以讀取方法
*參數:File類
*返回值:如果可以讀取返回0,否則返回-1
*/
public long checkOpen(File inFileA){
if(inFileA.canRead()){
return inFileA.length();
}else{
return -1;
}
}

/**
*獲得zip文件中的文件夾和文件總數
*參數:File類
*返回值:如果正常獲得則返回總數,否則返回-1
*/
public long getFilFoldCount(String infileA){
try{
int fileCount = 0;
zipInFile = new ZipInputStream(new FileInputStream(infileA));
while ((entry = zipInFile.getNextEntry()) != null){
if (entry.isDirectory()){
zipPathCount++;
}else{
zipFileCount++;
}
fileCount++;
}
return fileCount;
}catch(IOException e){
e.printStackTrace();
return -1;
}
}

/**
*讀取zip文件清單函數
*參數:File類
*返回值:文件清單數組
*/
public String[] getFileList(String infileA){
try{
ZipInputStream AzipInFile = new ZipInputStream(new FileInputStream(infileA));
//創建數組對象
FileNameArray = new String[(int)getFilFoldCount(infileA)];

//將文件名清單傳入數組
int i = 0;
while ((entry = AzipInFile.getNextEntry()) != null){
FileNameArray[i++] = entry.getName();
}
return FileNameArray;
}catch(IOException e){
e.printStackTrace();
return null;
}
}

/**
*創建文件函數
*參數:File類
*返回值:如果創建成功返回0,否則返回-1
*/
public long writeFile(String outFileA,byte[] dataByte){
try{
if (initOutStream(outFileA) == 0){
writeData.write(dataByte);
fileDataOut.close();
return 0;
}else{
fileDataOut.close();
return -1;
}
}catch(IOException e){
e.printStackTrace();
return -1;
}
}

/**
*讀取文件內容函數
*參數:File類
*返回值:如果讀取成功則返回讀取數據的位元組數組,如果失敗則返回空值
*/
protected byte[] readFile(ZipEntry entryA,ZipInputStream zipFileA){
try{
long entryFilelen;
if (initInStream(zipFileA) == 0){
if ((entryFilelen = entryA.getSize()) >= 0){
byte[] entryFileData = new byte[(int)entryFilelen];
readData.readFully(entryFileData,0,(int)entryFilelen);
return entryFileData;
}else{
return null;
}
}else{
return null;
}
}catch(IOException e){
e.printStackTrace();
return null;
}
}

/**
*創建目錄函數
*參數:要創建目錄的路徑
*返回值:如果創建成功則返回0,否則返回-1
*/
public long createFolder(String dir){
File file = new File(dir);
if (file.mkdirs()) {
return 0;
}else{
return -1;
}
}

/**
*刪除文件
*參數:要刪除的文件
*返回值:如果刪除成功則返回0,要刪除的文件不存在返回-2
* 如果要刪除的是個路徑則返回-3,刪除失敗則返回-1
*/
public long deleteFile(String Apath) throws SecurityException {
File file = new File(Apath.trim());
//文件或路徑不存在
if (!file.exists()){
return -2;
}
//要刪除的是個路徑
if (!file.isFile()){
return -3;
}
//刪除
if (file.delete()){
return 0;
}else{
return -1;
}
}

/**
*刪除目錄
*參數:要刪除的目錄
*返回值:如果刪除成功則返回0,刪除失敗則返回-1
*/
public long deleteFolder(String Apath){
File file = new File(Apath);
//刪除
if (file.delete()){
return 0;
}else{
return -1;
}
}

/**
*判斷所要解壓的路徑是否存在同名文件
*參數:解壓路徑
*返回值:如果存在同名文件返回-1,否則返回0
*/
public long checkPathExists(String AreleasePath){
File file = new File(AreleasePath);
if (!file.exists()){
return 0;
}else{
return -1;
}
}

/**
*刪除zip中的文件
*參數:文件清單數組,釋放路徑
*返回值:如果刪除成功返回0,否則返回-1
*/
protected long deleteReleaseZipFile(String[] listFilePath,String releasePath){
long arrayLen,flagReturn;
int k = 0;
String tempPath;
//存放zip文件清單的路徑
String[] pathArray = new String[zipPathCount];
//刪除文件
arrayLen = listFilePath.length;
for(int i=0;i<(int)arrayLen;i++){
tempPath = releasePath.replace('\\','/') + listFilePath[i];
flagReturn = deleteFile(tempPath);
if (flagReturn == -2){
//什麼都不作
}else if (flagReturn == -3){
pathArray[k++] = tempPath;
}else if (flagReturn == -1){
return -1;
}
}
//刪除路徑
for(k = k - 1;k>=0;k--){
flagReturn = deleteFolder(pathArray[k]);
if (flagReturn == -1) return -1;
}
return 0;
}

/**
*獲得zip文件的最上層的文件夾名稱
*參數:zip文件路徑
*返回值:文件夾名稱,如果失敗則返回null
*/
public String getZipRoot(String infileA){
String rootName;
try{
FileInputStream tempfile = new FileInputStream(infileA);
ZipInputStream AzipInFile = new ZipInputStream(tempfile);
ZipEntry Aentry;
Aentry = AzipInFile.getNextEntry();
rootName = Aentry.getName();
tempfile.close();
AzipInFile.close();
return rootName;
}catch(IOException e){
e.printStackTrace();
return null;
}
}

/**
*釋放流,釋放佔用資源
*/
protected void closeStream() throws Exception{
fileDataIn.close();
fileDataOut.close();
zipInFile.close();
writeData.flush();
}

/**
*解壓函數
*對用戶的zip文件路徑和解壓路徑進行判斷,是否存在和打開
*在輸入解壓路徑時如果輸入"/"則在和zip文件存放的統計目錄下進行解壓
*返回值:0表示釋放成功
* -1 表示您所要解壓的文件不存在、
* -2表示您所要解壓的文件不能被打開、
* -3您所要釋放的路徑不存在、
* -4您所創建文件目錄失敗、
* -5寫入文件失敗、
* -6表示所要釋放的文件已經存在、
* -50表示文件讀取異常
*/
public long releaseHandle() throws Exception{
File inFile = new File(inFilePath);
File outFile = new File(releaseFilePath);
String tempFile;
String zipPath;
String zipRootPath;
String tempPathParent; //存放釋放路徑
byte[] zipEntryFileData;

//作有效性判斷
if (checkFile(inFile) == -1) {
return -1;}
if (checkOpen(inFile) == -1) {
return -2;}
//不是解壓再當前目錄下時對路徑作有效性檢驗
if (!releaseFilePath.equals("/")){
//解壓在用戶指定目錄下
if (checkFile(outFile) == -1) {
return -3;}
}
//獲得標准釋放路徑
if (!releaseFilePath.equals("/")) {
tempPathParent = releaseFilePath.replace('\\','/')+ "/";
}else{
tempPathParent = inFile.getParent().replace('\\','/')+ "/";
}
//獲得zip文件中的入口清單
FileNameArray = getFileList(inFilePath);
//獲得zip文件的最上層目錄
zipRootPath = getZipRoot(inFilePath);
//
fileDataIn = new FileInputStream(inFilePath);
zipInFile = new ZipInputStream(fileDataIn);
//判斷是否已經存在要釋放的文件夾
if (zipRootPath.lastIndexOf("/") > 0 ){
if (checkPathExists(tempPathParent +
zipRootPath.substring(0,zipRootPath.lastIndexOf("/"))) == -1){
return -6;
}
}else{
if (checkPathExists(tempPathParent + zipRootPath) == -1){
return -6;
}
}

//
try{
//創建文件夾和文件
int i = 0;
while ((entry = zipInFile.getNextEntry()) != null){
if (entry.isDirectory()){
//創建目錄
zipPath = tempPathParent + FileNameArray[i];
zipPath = zipPath.substring(0,zipPath.lastIndexOf("/"));
if (createFolder(zipPath) == -1){
closeStream();
deleteReleaseZipFile(FileNameArray,tempPathParent);
return -4;
}

}else{
//讀取文件數據
zipEntryFileData = readFile(entry,zipInFile);
//向文件寫數據
tempFile = tempPathParent + FileNameArray[i];
//寫入文件
if (writeFile(tempFile,zipEntryFileData) == -1){
closeStream();
deleteReleaseZipFile(FileNameArray,tempPathParent);
return -5;
}
}
i++;
}
//釋放資源
closeStream();
return 0;
}catch(Exception e){
closeStream();
deleteReleaseZipFile(FileNameArray,tempPathParent);
e.printStackTrace();
return -50;
}
}
/**
*演示函數
*根據用戶輸入的路徑對文件進行解壓
*/
public static void main(String args[]) throws Exception {

long flag; //返回標志
String inPath,releasePath;

//獲得用戶輸入信息
BufferedReader userInput = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("請輸入zip文件路徑:");
inPath = userInput.readLine();
System.out.println("請輸入保存路徑:");
releasePath = userInput.readLine();
userInput.close();

//執行解壓縮
zipFileRelease pceraZip = new zipFileRelease(inPath,releasePath);
flag = pceraZip.releaseHandle();

//出錯信息列印
if (flag == 0) System.out.println("釋放成功!!!");
if (flag == -1) System.out.println("您所要解壓的文件不存在!");
if (flag == -2) System.out.println("您所要解壓的文件不能被打開!");
if (flag == -3) System.out.println("您所要釋放的路徑不存在!");
if (flag == -4) System.out.println("您所創建文件目錄失敗!");
if (flag == -5) System.out.println("寫入文件失敗!");
if (flag == -6) System.out.println("文件已經存在!");
if (flag == -50) System.out.println("文件讀取異常!");
}
}

㈥ 想用java做個壓縮和解壓縮的小程序,不知道如何實現。

root :釋放文件路徑 zipfile:待解壓文件的路徑 file:待解壓文件的文件名
public void unzip(File root, File zipfile, String file) throws Exception {

// 解壓文件不存在時返回
if (!zipfile.exists()) {
return;
}
// 釋放目錄不存時創建
if (!root.exists()) {
root.mkdirs();
}
// 釋放目錄不為目錄時返回
if (!root.isDirectory()) {
return;
}

FileInputStream fin = new FileInputStream(zipfile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry entry = null;

while ((entry = zin.getNextEntry()) != null) {
if (!entry.getName().endsWith(file)) {
continue;
}
File tmp = new File(root, entry.getName());
if (entry.isDirectory()) {
tmp.mkdirs();
} else {
byte[] buff = new byte[4096];
int len = 0;
tmp.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(tmp);
while ((len = zin.read(buff)) != -1) {
fout.write(buff, 0, len);
}
zin.closeEntry();
fout.close();
}
}
}

㈦ java 如何壓縮文件

樓主是說解壓了的文件大小隻有33.1MB,但是卻佔了51.2MB的空間嗎?
如果是這個意思的話,那我要告訴樓主,首先這個問題和JAVA沒有關系,根據你的截圖,可以斷定你用的是FAT32文件系統。這只是文件存儲的形式,很正常。
簡單的說,磁碟存儲數據的最小單位是簇,比方說你的簇大小為128K,一個簇只能存放一個文件,然後你的一個文件只有16K,它佔了這個簇,然後還有112K沒有用,是吧。但是那112K就不能再存放其它文件了。如果要存放其它文件,就要佔另一個簇。
樓主,懂了吧,這跟簇的大小有關,但是也不是簇越小越好,簇越小,讀寫性能都有所下降。這是正常現象。如果你非覺得不舒服,那就用NTFS文件系統吧,把壓縮打開,就不會有這種情況了,希望對你有幫助

㈧ 如何使用JAVA代碼壓縮pdf文件

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

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

㈨ java 如何壓縮文件

樓主是說解壓了的文件大小隻有33.1MB,但是卻佔了51.2MB的空間嗎?
如果是這個意思的話,那我要告訴樓主,首先這個問題和JAVA沒有關系,根據你的截圖,可以斷定你用的是FAT32文件系統。這只是文件存儲的形式,很正常。
簡單的說,磁碟存儲數據的最小單位是簇,比方說你的簇大小為128K,一個簇只能存放一個文件,然後你的一個文件只有16K,它佔了這個簇,然後還有112K沒有用,是吧。但是那112K就不能再存放其它文件了。如果要存放其它文件,就要佔另一個簇。
樓主,懂了吧,這跟簇的大小有關,但是也不是簇越小越好,簇越小,讀寫性能都有所下降。這是正常現象。如果你非覺得不舒服,那就用NTFS文件系統吧,把壓縮打開,就不會有這種情況了,希望對你有幫助

㈩ java將File壓縮成zip

ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("d:\\test.zip"));
String test1="test1";
String test2="test2";
byte[] bytes1 = test1.getBytes("UTF-8");
byte[] bytes2 = test2.getBytes("UTF-8");

ZipEntry z1 = new ZipEntry("test1.txt");
zos.putNextEntry(z1);
zos.write(bytes1);
ZipEntry z2 = new ZipEntry("text2.txt");
zos.putNextEntry(z2);
zos.write(bytes2);
zos.closeEntry();
zos.close();

//流可以自己獲取

//java默認的包不支持中文(亂碼)

//使用apache的ZipOutputStream進行zip壓縮
是否可以解決您的問題?

閱讀全文

與java壓縮數據相關的資料

熱點內容
動作片愛情在線免費觀看 瀏覽:1002
騰飛投資理財分紅源碼 瀏覽:854
windows打開埠命令 瀏覽:93
php獲取數組第一個元素key 瀏覽:488
重生二戰德國元首希特勒 瀏覽:135
被迫成為言情文的炮灰男小三 瀏覽:646
風月片在線觀看視頻 瀏覽:427
如何更新搶修app 瀏覽:711
aqdya愛情網 瀏覽:743
韓國倫理電影正宇 瀏覽:887
男主角在劇里叫諾亞的電影 瀏覽:794
集結號的男主 瀏覽:415
魔獸世界懷舊服會長移交命令 瀏覽:100
中文字幕在線觀看的網站 瀏覽:473
主角上自己女兒的小說 瀏覽:112
javaextjs文件上傳 瀏覽:28
有哪些佛教電影 瀏覽:149
成人劇情小說 瀏覽:113
國外免費小電影網站 瀏覽:909
怎麼把文件夾百度網盤 瀏覽:788