当前位置:主页 > 软件编程 > JAVA代码 >

Java删除指定文件夹下的所有内容的方法(包括此文件夹)

时间:2021-02-26 10:54:47 | 栏目:JAVA代码 | 点击:

如下所示:

// 删除文件夹
	private static void deleteDirectory(File file) {
		if (file.isFile()) {// 表示该文件不是文件夹
			file.delete();
		} else {
			// 首先得到当前的路径
			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);
	}

您可能感兴趣的文章:

相关文章