Java on Line
和java的日子!
BlogJava
::
首頁(yè)
::
新隨筆
::
聯(lián)系
::
聚合
::
管理
::
8 隨筆 :: 0 文章 :: 28 評(píng)論 :: 0 Trackbacks
<
2013年10月
>
日
一
二
三
四
五
六
29
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
公告
謝謝您的關(guān)注!!!
留言簿
(1)
給我留言
查看公開(kāi)留言
查看私人留言
隨筆分類(lèi)
(8)
Java基礎(chǔ)(5)
(rss)
Java收集
(rss)
個(gè)人隨筆(1)
(rss)
開(kāi)發(fā)收集(2)
(rss)
隨筆檔案
(8)
2008年4月 (2)
2008年3月 (1)
2007年10月 (1)
2007年9月 (1)
2007年8月 (3)
相關(guān)連接
expert
struts2學(xué)習(xí)
Sun中國(guó)技術(shù)社區(qū)
我的Blog
日期控件
搜索
最新評(píng)論
1.?re: 用java壓縮文件夾/文件
YASUO
--XURUIYANG
2.?re: 用java壓縮文件夾/文件
壓縮文件夾時(shí),有問(wèn)題吧,會(huì)多出一個(gè)文件夾來(lái)。
--路人
3.?re: 用java壓縮文件夾/文件
@ne_akari
你個(gè)二逼,自己好好看看再說(shuō)
--路人
4.?re: 用java刪除文件夾里的所有文件[未登錄](méi)
thanks.
--tao
5.?寫(xiě)的真不錯(cuò)
寫(xiě)的真不錯(cuò),代碼拿出來(lái)就能執(zhí)行,感謝感謝啊!
--沈坤林
用java刪除文件夾里的所有文件
import
java.io.File;
public
class
Test
{
public
static
void
main(String args[])
{
Test t
=
new
Test();
delFolder(
"
c:/bb
"
);
System.out.println(
"
deleted
"
);
}
//
刪除文件夾
//
param folderPath 文件夾完整絕對(duì)路徑
public
static
void
delFolder(String folderPath)
{
try
{
delAllFile(folderPath);
//
刪除完里面所有內(nèi)容
String filePath
=
folderPath;
filePath
=
filePath.toString();
java.io.File myFilePath
=
new
java.io.File(filePath);
myFilePath.delete();
//
刪除空文件夾
}
catch
(Exception e)
{
e.printStackTrace();
}
}
//
刪除指定文件夾下所有文件
//
param path 文件夾完整絕對(duì)路徑
public
static
boolean
delAllFile(String path)
{
boolean
flag
=
false
;
File file
=
new
File(path);
if
(
!
file.exists())
{
return
flag;
}
if
(
!
file.isDirectory())
{
return
flag;
}
String[] tempList
=
file.list();
File temp
=
null
;
for
(
int
i
=
0
; i
<
tempList.length; i
++
)
{
if
(path.endsWith(File.separator))
{
temp
=
new
File(path
+
tempList[i]);
}
else
{
temp
=
new
File(path
+
File.separator
+
tempList[i]);
}
if
(temp.isFile())
{
temp.delete();
}
if
(temp.isDirectory())
{
delAllFile(path
+
"
/
"
+
tempList[i]);
//
先刪除文件夾里面的文件
delFolder(path
+
"
/
"
+
tempList[i]);
//
再刪除空文件夾
flag
=
true
;
}
}
return
flag;
}
}
posted on 2007-10-12 16:19
陳東
閱讀(18635)
評(píng)論(1)
編輯
收藏
所屬分類(lèi):
Java基礎(chǔ)
評(píng)論
#
re: 用java刪除文件夾里的所有文件[未登錄](méi)
2013-10-01 01:03
tao
thanks.
回復(fù)
更多評(píng)論
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
相關(guān)文章:
JDBC連接各種數(shù)據(jù)庫(kù)方法
將一個(gè)字符串里的數(shù)字,分割后進(jìn)行排序
用java刪除文件夾里的所有文件
用java解壓文件夾
用java壓縮文件夾/文件
Powered by:
BlogJava
Copyright © 陳東
主站蜘蛛池模板:
广南县
|
金门县
|
泗阳县
|
龙南县
|
潜山县
|
沧州市
|
浪卡子县
|
舞钢市
|
北辰区
|
田林县
|
吉林市
|
莱州市
|
海口市
|
易门县
|
大宁县
|
桑植县
|
嘉禾县
|
万州区
|
万源市
|
浦县
|
黎川县
|
宿迁市
|
门头沟区
|
屯门区
|
重庆市
|
利津县
|
北票市
|
石河子市
|
织金县
|
九江市
|
湟源县
|
周宁县
|
玛多县
|
岱山县
|
禄丰县
|
峨山
|
安阳市
|
海口市
|
会东县
|
宽城
|
娄烦县
|