/**
* 壓縮檔案或目錄
** @param frompath 待壓縮檔案或路徑
* @param topath 壓縮檔案,不要是目錄,如 xx.zip
*/public
static
void
compress
(string frompath, string topath) throws ioexception
try(
fileoutputstream outputstream =
newfileoutputstream
(tofile)
; checkedoutputstream checkedoutputstream =
newcheckedoutputstream
(outputstream,
newcrc32()
);zipoutputstream zipoutputstream =
newzipoutputstream
(checkedoutputstream))}
private
static
void
compress
(file file, zipoutputstream zipout, string basedir) throws ioexception
else
}private
static
void
compressdirectory
(file dir, zipoutputstream zipout, string basedir) throws ioexception }}
private
static
void
compressfile
(file file, zipoutputstream zipout, string basedir) throws ioexception
try(bufferedinputstream bis =
newbufferedinputstream
(new
fileinputstream
(file)))
}}
/**
* 解壓檔案/資料夾(壓縮包下存在資料夾的)
* 檔案只能是壓縮包可不存在資料夾
** @param srcpath 壓縮包完整路徑
* @param dest 解壓指定的目錄
* @throws exception
*/public
static
void
decompress
(string srcpath, string dest) throws exception
zipfile zf =
newzipfile
(file)
; enumeration entries = zf.
entries()
; zipentry entry =
null
;while
(entries.
hasmoreelements()
)else
f.createnewfile()
;// 將壓縮檔案內容寫入到這個檔案中
inputstream is = zf.
getinputstream
(entry)
; fileoutputstream fos =
newfileoutputstream
(f);
int count;
byte[
] buf =
newbyte
[8192];
while
((count = is.
read
(buf))!=
-1) is.
close()
; fos.
close()
;}}}
/**
* 獲取資料夾下符合檔案格式的真實檔名稱
** @param path 資料夾路徑
* @param listfilename 集合
* @param filetype 檔案字尾格式
*/public
static
void
getallfileurlname
(string path, list listfilename, string filetype)
else
if(names[i]
.substring
(names[i]
.lastindexof
("."))
.equalsignorecase
(filetype)
)else
} listfilename.
addall
(arrays.
aslist
(completnames));
listfilename.
removeall
(collections.
singleton
(null))
;}}
/**
* 遞迴刪除檔案或目錄
** @param filepath 檔案或目錄
*/public
static
void
delete
(string filepath)
}try
catch
(ioexception e)
}
/**
* 獲取檔案型別
** @param file 檔案
* @return 檔案型別
* 檔案存放的完整路徑集合
*/@apimodelproperty
(value =
"檔案存放的完整路徑集合"
,name =
"srcfiles"
,required =
true
)public list srcfiles;
/** * zip壓縮包的名稱
*/@apimodelproperty
(value =
"zip壓縮包的名稱,不需要字尾"
,name =
"zipfilename"
,required =
true
)public string zipfilename;
壓縮 解壓檔案
tar cvf abc.tar abc 把abc這個目錄打包,生成乙個檔案名字叫abc.tar tar xvf abc.tar 把abc.tar這個檔案中所有的檔案提取出來 tar只負責把多個檔案打包,而不負責壓縮 gzip abc.tar 把abc.tar檔案壓縮為abc.tar.gz gzip ...
LINUX壓縮 解壓檔案
01 tar格式 解包 tar xvf filename.tar 打包 tar cvf filename.tar dirname 注 tar是打包,不是壓縮!02 gz格式 解壓1 gunzip filename.gz 解壓2 gzip d filename.gz 壓 縮 gzip filename...
檔案壓縮與解壓
檔案的壓縮 1.讀取檔案的內容 2.統計每個字元出現的次數 int read while read bis.read 1 直至讀到檔案結束 arrays為運算元組的工具類 collections為操作集合工具類 bis.close 3.構建哈弗曼樹,生成哈夫曼編碼 if node.getleftno...