public static void compress(string source, string destinct)
throws ioexception, interruptedexception
/******壓縮方法二(channel)-begin******/
/*file zipfile = new file(destinct);
try (zipoutputstream zipout = new zipoutputstream(new fileoutputstream(zipfile));
writablebytechannel writablebytechannel = channels.newchannel(zipout))
try (filechannel filechannel = new fileinputstream(filepath).getchannel())
}} catch (exception e) */
/******壓縮方法二-end******/
/******壓縮方法一(buffered傳輸) begin******/
zipoutputstream zos = new zipoutputstream(new fileoutputstream(
new file(destinct)));
zos.setlevel(0);//採用最快等級壓縮,壓縮檔案大小最大
byte buffere = new byte[8192];
int length;
bufferedinputstream bis;
for (int i = 0; i < filelist.size(); i++)
zos.putnextentry(new zipentry(entryname));
bis = new bufferedinputstream(new fileinputstream(file));
while ((length=bis.read(buffere))!=-1)
bis.close();
zos.closeentry();
}zos.close();
/******壓縮方法一 end******/
/******壓縮方法三(ziparchiveoutputstream) begin******/
/*if (filelist != null && filelist.size() > 0)
inputstream is = null;
try
zaos.closearchiveentry();
} catch (exception e) finally }}
zaos.finish();
} catch (exception e) finally
} catch (ioexception e)
}}*/
/******壓縮方法三 end*******/
}/**
* 遞迴獲得該檔案下所有檔名(不包括目錄名)
** @param file
* @return
*/private static listloadfilename(file file)
if (file.isdirectory())
for (file f : file.listfiles())
}return filenamelist;
}/**
* 獲得zip entry 字串
** @param base
* @param file
* @return
*/private static string getentryname(string base, file file)
return filename.substring(basefile.getparent().length() + 1);
}
C 的幾種壓縮檔案方法
1.將指定目錄下的檔案壓縮為.tar格式,並儲存到指定路徑 tar 將制定目錄下的檔案壓縮為tar檔案 源目錄d images 目標目錄tar檔案f tar aaa.tar public static void compresstarfile string in,string out if arch...
幾種壓縮演算法
首先應該理解英文本母在計算機中也是按照乙個個的位元組進行儲存的,也就是char型別的大小,對應於ascii編碼的方式。rle run length encoding 演算法 行程長度編碼!演算法的大致思想就是將一串連續的英文本母中連續重複出現的次數計算出來,然後只是使用對應的單個字元和出現的次數來進...
壓縮mssql日誌檔案的方法
壓縮日誌及資料庫檔案大小 1.清空日誌 dump transaction 庫名 with no log 2.截斷事務日誌 backup log 資料庫名 with no log 3.收縮資料庫檔案 如果不壓縮,資料庫的檔案不會減小 企業管理器 右鍵你要壓縮的資料庫 所有任務 收縮資料庫 收縮檔案 選...