Java删除指定文件

1.Java删除指定文件夹下的所有内容(包括此文件夹) 递归删除,通俗易懂。

转至:https://blog.csdn.net/kpchen_0508/article/details/48729653

 

	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);
	}

 

你可能感兴趣的:(Java删除指定文件)