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
閱讀(247)
評論(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
搜索
積分與排名
積分 - 40351
排名 - 1158
最新評論
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命令整理(14650)
2.?Maven起步——教你開始使用Maven二(圖)(3446)
3.? [轉][國內著名大學][課件大全][在線點播](1832)
4.?JIRA安裝日志(1425)
5.?Emacs 中文指南(1376)
評論排行榜
1.? [轉][國內著名大學][課件大全][在線點播](2)
2.?提交后按鈕失效(1)
3.?常用Emacs命令整理(1)
4.?聽《紅色搖滾》中國際歌,讓人熱血沸騰(1)
5.?利用 Spring 和 EHCache 緩存結果(翻譯)選擇自 rosen 的 Blog(1)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 Rain's Blog
主站蜘蛛池模板:
久久久久久亚洲精品成人
|
中文字幕不卡亚洲
|
国产香蕉免费精品视频
|
久久精品亚洲综合专区
|
国产一区二区三区免费观看在线
|
在线精品亚洲一区二区三区
|
亚洲免费视频一区二区三区
|
最新亚洲成av人免费看
|
一出一进一爽一粗一大视频免费的
|
免费永久看黄在线观看app
|
国内成人精品亚洲日本语音
|
亚洲AV蜜桃永久无码精品
|
九一在线完整视频免费观看
|
亚洲日韩精品A∨片无码
|
二个人看的www免费视频
|
亚洲不卡av不卡一区二区
|
日本免费久久久久久久网站
|
亚洲精品高清国产一久久
|
91网站免费观看
|
亚洲精品欧美综合四区
|
免费一区二区三区四区五区
|
free哆拍拍免费永久视频
|
亚洲成人在线电影
|
免费A级毛片无码免费视
|
国产精品久久亚洲一区二区
|
国产日产亚洲系列
|
91成人免费观看
|
亚洲国产欧洲综合997久久
|
亚洲VA综合VA国产产VA中
|
成人爽a毛片免费
|
亚洲人成电影网站久久
|
内射无码专区久久亚洲
|
性xxxxx大片免费视频
|
国产人成亚洲第一网站在线播放
|
亚洲成年看片在线观看
|
在线观看免费av网站
|
国产成人亚洲午夜电影
|
日韩精品一区二区亚洲AV观看
|
成人黄软件网18免费下载成人黄18免费视频
|
99久久综合精品免费
|
亚洲av永久无码一区二区三区
|