如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
private static void deleteDirectory(File file) { if (file.isFile()) { // 表示該文件不是文件夾 file.delete(); } else { // 首先得到當(dāng)前的路徑 String[] childFilePaths = file.list(); for (String childFilePath : childFilePaths) { File childFile = new File(file.getAbsolutePath() + "/" + childFilePath); deleteDirectory(childFile); } file.delete(); } } public static void main(String[] args) { File del_file = new File( "D:/Test/ibs" + "/temp/" ); deleteDirectory(del_file); } |
以上這篇Java刪除指定文件夾下的所有內(nèi)容的方法(包括此文件夾) 就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持服務(wù)器之家。