码迷,mamicode.com
首页 > 其他好文 > 详细

删除指定文件或文件夹

时间:2015-05-19 10:36:48      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:删除指定文件或文件夹

	public static void delFolder(String dirPath) {
		try {
			dAllFile(dirPath);  
			String fpath = dirPath;
			 File mPath = new File(fpath);
			boolean tempFlag = mPath.delete();  
		} catch (Exception ex) {
			Write.debug(""+ex.getMessage());
		}
	}

	public static boolean dAllFile(String fPath) {
		 
		File myFile = new File(fPath);
		if (!myFile.exists()) {
			return false;
		}
		if (!myFile.isDirectory()) {
			return false;
		}
		String[] tList = myFile.list();
		File tempFile = null;
		for (int i = 0; i < tList.length; i++) {
			if (fPath.endsWith(File.separator)) {
				tempFile = new File(fPath + tList[i]);
			} else {
				tempFile = new File(fPath + File.separator + tList[i]);
			}
			if (tempFile.isFile()) {
				boolean tempFlag = tempFile.delete();
			}
			if (tempFile.isDirectory()) {
				dAllFile(fPath + "/" + tList[i]); 
				delFolder(fPath + "/" + tList[i]); 
				return  true;
			}
		}
		 return false; 
	}

删除指定文件或文件夹

标签:删除指定文件或文件夹

原文地址:http://blog.csdn.net/xiaoyi_tdcq/article/details/45840881

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