Rain's Blog
The man who has made up his mind to win will never say“Impossible”. ——Napoleon
BlogJava
|
首頁
|
發新隨筆
|
發新文章
|
聯系
|
聚合
|
管理
隨筆:43 文章:0 評論:6 引用:0
解壓文件
?1
package
?zhenyu.tools.file;
?2
?3
import
?java.io.
*
;
?4
?5
import
?java.util.
*
;
?6
import
?java.util.zip.
*
;
?7
?8
?9
public
?
class
?Unzip?
{
10
????
public
?Unzip()?
{
11
????}
12
13
????
public
?
static
?
void
?main(String[]?args)?
{
14
????????Unzip?unzip?
=
?
new
?Unzip();
15
????????unzip.UnzipFile(
"
D:\\tmp.zip
"
,?
"
e:\\tmp
"
);
16
????}
17
18
????
public
?
static
?
final
?
void
?copyInputStream(InputStream?in,?OutputStream?out)
19
????????
throws
?IOException?
{
20
????????
byte
[]?buffer?
=
?
new
?
byte
[
1024
];
21
????????
int
?len;
22
23
????????
while
?((len?
=
?in.read(buffer))?
>=
?
0
)
24
????????????out.write(buffer,?
0
,?len);
25
26
????????in.close();
27
????????out.close();
28
????}
29
30
????
private
?
void
?UnzipFile(String?from,?String?to)?
{
31
????????Enumeration?entries;
32
????????ZipFile?zipFile;
33
34
????????
if
?(from?
==
?
null
)?
{
35
????????????System.err.println(
"
Usage:?Unzip?zipfile
"
);
36
37
????????????
return
;
38
????????}
39
40
????????
try
?
{
41
????????????zipFile?
=
?
new
?ZipFile(from);
42
????????????entries?
=
?zipFile.entries();
43
44
????????????
while
?(entries.hasMoreElements())?
{
45
????????????????ZipEntry?entry?
=
?(ZipEntry)?entries.nextElement();
46
????????????????System.out.println(entry.getName());
47
48
????????????????
if
?(entry.getName().lastIndexOf(
"
\\
"
)?
!=
?
-
1
)?
{
49
50
????????????????????System.out.println(
"
Extracting?directory:?
"
?
+
?to?
+
51
????????????????????????File.separator?
+
?entry.getName());
52
53
????????????????????String?txt;
54
????????????????????StringTokenizer?st?
=
?
new
?StringTokenizer(entry.getName(),
55
????????????????????????????
"
\\
"
);
56
????????????????????
for
?(
int
?i?
=
?
0
;?st.hasMoreTokens()
&&
i
<
st.countTokens();?i
++
)?
{
57
????????????????????????txt?
=
?st.nextToken().trim();
58
????????????????????????
if
?(to.endsWith(
"
\\
"
))?
{
59
????????????????????????????File?myFilePath?
=
?
new
?File(to?
+
?txt);
60
61
????????????????????????????
if
?(
!
myFilePath.exists())?
{
62
????????????????????????????????myFilePath.mkdir();
63
????????????????????????????}
64
????????????????????????}
?
else
?
{
65
????????????????????????????File?myFilePath?
=
?
new
?File(to?
+
?File.separator?
+
66
????????????????????????????????????txt);
67
68
????????????????????????????
if
?(
!
myFilePath.exists())?
{
69
????????????????????????????????myFilePath.mkdir();
70
????????????????????????????}
71
????????????????????????}
72
????????????????????}
73
????????????????}
74
75
????????????????System.out.println(
"
Extracting?file:?
"
?
+
?to?
+
?File.separator?
+
76
????????????????????entry.getName());
77
????????????????System.out.println(
"
--------------------------------------
"
);
78
79
????????????????????????????????copyInputStream(zipFile.getInputStream(entry),
80
????????????????????????????????????
new
?BufferedOutputStream(
81
????????????????????????????????????????
new
?FileOutputStream(to?
+
?File.separator?
+
?entry.getName())));
82
????????????}
83
84
????????????zipFile.close();
85
????????}
?
catch
?(IOException?ioe)?
{
86
????????????System.err.println(
"
Unhandled?exception:
"
);
87
????????????ioe.printStackTrace();
88
89
????????????
return
;
90
????????}
91
????}
92
}
93
壓縮包文件結構:
|-tem
?????? |-folderA
?????????????????? |-filea
????????????????? ?|-fileb
?????????????????? |-filec
?????? |-filed
解壓后文件結構:
|-tem
?????? |-folderA
?????????????????? |-filea
????????????????? ?|-fileb
?????????????????? |-filec
?????? |-filed
發表于 2006-05-26 19:54
Rain's Blog
閱讀(255)
評論(0)
編輯
收藏
所屬分類:
JAVA
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
A Spring Jump Start.Part.IV
A Spring Jump Start.Part.III
A Spring Jump Start.Part.II
A Spring Jump Start.Part.I
解壓文件
[轉載]jsp導出excel Author:piliskys
文件操作(jsp)
<
2006年5月
>
日
一
二
三
四
五
六
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
公告
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆分類
(38)
Ajax(1)
(rss)
C#(3)
(rss)
CSS
(rss)
DataBase(3)
(rss)
Eclipse(5)
(rss)
Hibernate(1)
(rss)
JAVA(7)
(rss)
Javascript(9)
(rss)
SCM(1)
(rss)
Test(1)
(rss)
WorkFlow(1)
(rss)
收藏(6)
(rss)
隨筆檔案
(43)
2006年12月 (1)
2006年10月 (5)
2006年9月 (1)
2006年8月 (4)
2006年7月 (9)
2006年6月 (2)
2006年5月 (2)
2006年4月 (4)
2006年3月 (2)
2006年2月 (4)
2006年1月 (9)
收藏夾
(2)
Ajax(2)
(rss)
Ajax
Autoassist
behaviour
Rico
C#
博客們
blueoxygen
Brian Sun @ 爬樹的泡泡
(rss)
java node
(rss)
piliskys
(rss)
snoics
(rss)
江南白衣
(rss)
軟件人生 : Weblog
最新隨筆
1.?Eclipse RCP Tips
2.?Eclipse keyboard shortcuts
3.?Eclipse標準快捷鍵
4.?Emacs 中文指南
5.?常用Emacs命令整理
6.?Emacs 快捷鍵
7.?Oracle9i xdb 與tomcat8080端口沖突(摘自http://www.tkk7.com/Victor/)
8.?Atlas DragOverlayExtender 試用小記
9.?Resharper 2.0
10.?Multiple Main Entry Points in Visual Studio.NET
搜索
積分與排名
積分 - 40625
排名 - 1156
最新評論
1.?re: 提交后按鈕失效[未登錄]
ddddd
--ddd
2.?re: 常用Emacs命令整理
請問我要將clipboard里的文字粘貼199遍在某處該怎么做?
--youke
3.?re: [轉][國內著名大學][課件大全][在線點播][未登錄]
好好的東東,可為什么我打不開啊~~~~
--七七001
4.?re: [轉][國內著名大學][課件大全][在線點播][未登錄]
hao hao
--111
5.?re: 利用 Spring 和 EHCache 緩存結果(翻譯)選擇自 rosen 的 Blog
評論內容較長,點擊標題查看
--Rosen
閱讀排行榜
1.?常用Emacs命令整理(14671)
2.?Maven起步——教你開始使用Maven二(圖)(3451)
3.? [轉][國內著名大學][課件大全][在線點播](1838)
4.?JIRA安裝日志(1433)
5.?Emacs 中文指南(1385)
評論排行榜
1.? [轉][國內著名大學][課件大全][在線點播](2)
2.?提交后按鈕失效(1)
3.?常用Emacs命令整理(1)
4.?聽《紅色搖滾》中國際歌,讓人熱血沸騰(1)
5.?利用 Spring 和 EHCache 緩存結果(翻譯)選擇自 rosen 的 Blog(1)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 Rain's Blog
主站蜘蛛池模板:
亚洲欧洲精品成人久久曰
|
色老头综合免费视频
|
高清国语自产拍免费视频国产
|
亚洲成av人片在www鸭子
|
国产成人精品久久亚洲
|
最近免费中文字幕高清大全
|
亚洲精品色播一区二区
|
国产偷v国产偷v亚洲高清
|
国产精品爱啪在线线免费观看
|
美女被羞羞网站免费下载
|
亚洲成av人片天堂网
|
免费理论片51人人看电影
|
久久九九全国免费
|
亚洲人成色在线观看
|
久久亚洲欧洲国产综合
|
一二三四在线播放免费观看中文版视频
|
亚洲第一网站男人都懂
|
91香蕉国产线观看免费全集
|
亚洲熟妇丰满xxxxx
|
亚洲AV永久青草无码精品
|
尤物永久免费AV无码网站
|
99蜜桃在线观看免费视频网站
|
jzzijzzij在线观看亚洲熟妇
|
久久久久久亚洲Av无码精品专口
|
国产hs免费高清在线观看
|
亚洲免费电影网站
|
caoporm碰最新免费公开视频
|
中国一级毛片免费看视频
|
亚洲精品美女久久7777777
|
国产精品久久久亚洲
|
国产美女无遮挡免费视频网站
|
亚洲综合丁香婷婷六月香
|
丁香五月亚洲综合深深爱
|
亚洲成在人线aⅴ免费毛片
|
久久免费国产视频
|
一区在线免费观看
|
亚洲国产精品成人AV在线
|
亚洲激情校园春色
|
午夜亚洲www湿好大
|
亚洲中文字幕久久精品无码喷水
|
国内自产少妇自拍区免费
|