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
搜索
積分與排名
積分 - 40622
排名 - 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
主站蜘蛛池模板:
国产亚洲精品久久久久秋霞
|
老司机精品免费视频
|
日本一区免费电影
|
亚洲人成色777777精品
|
最近免费中文字幕大全
|
亚洲AV成人影视在线观看
|
免费国产黄线在线观看
|
亚洲一区二区免费视频
|
国产成人A在线观看视频免费
|
亚洲一区二区三区写真
|
久久精品视频免费看
|
亚洲一区二区在线免费观看
|
**一级毛片免费完整视
|
亚洲乱码一区av春药高潮
|
最近的中文字幕大全免费版
|
亚洲精品V天堂中文字幕
|
免费又黄又爽的视频
|
国产99精品一区二区三区免费
|
国产亚洲精品岁国产微拍精品
|
久9久9精品免费观看
|
亚洲伊人久久大香线蕉影院
|
免费爱爱的视频太爽了
|
成年大片免费高清在线看黄
|
亚洲爱情岛论坛永久
|
成人特黄a级毛片免费视频
|
特级无码毛片免费视频
|
国产av无码专区亚洲av桃花庵
|
黄色免费网站网址
|
羞羞视频在线免费观看
|
亚洲三区在线观看无套内射
|
波多野结衣免费在线观看
|
粉色视频免费入口
|
无码专区—VA亚洲V天堂
|
国内大片在线免费看
|
a毛片免费观看完整
|
youjizz亚洲
|
亚洲无码在线播放
|
我要看WWW免费看插插视频
|
jizz日本免费
|
久久亚洲国产成人影院
|
伊伊人成亚洲综合人网7777
|