码迷,mamicode.com
首页 > 编程语言 > 详细

用java实现删除目录

时间:2020-05-30 20:01:20      阅读:54      评论:0      收藏:0      [点我收藏+]

标签:system   let   new   ati   files   else   ring   file   string   

用java实现删除目录

	public static void main(String[] args) {
		try {
			String strFolder = "D:\\aa";
			deleteFile(new File(strFolder));

			System.out.println("Delete Successful!");
		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.out.println("Delete Fail!");
		}
	}

	public static void deleteFile(File file) {

		if (file == null || !file.exists()) {
			return;
		}

		File[] files = file.listFiles();
		for (File f : files) {
			if (f.isDirectory()) {
				deleteFile(f);
			} else {
				f.delete();
			}
		}
		file.delete();
	}

  

用java实现删除目录

标签:system   let   new   ati   files   else   ring   file   string   

原文地址:https://www.cnblogs.com/wzihan/p/12994367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!