All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.xiaoyuge5201.weixin.MetrialUtil Maven / Gradle / Ivy

There is a newer version: 1.3.5
Show newest version
package com.github.xiaoyuge5201.weixin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * 微信永久素材
 * 
 * @author CSSARSARI
 *
 */
public class MetrialUtil {
	private  static Logger log = LoggerFactory.getLogger(MetrialUtil.class);
	public static void del_file(String url) {
		File file = new File(url);
		// 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
		if (file.exists() && file.isFile()) {
			if (file.delete()) {
				log.info("删除单个文件" + url + "成功!");
			} else {
				log.info("删除单个文件" + url + "失败!");
			}
		} else {
			log.info("删除单个文件失败:" + url + "不存在!");
		}
	}

	/**
	 * 删除指定文件夹下面的所有文件
	 * @param file
	 */
	public static void deleteAll(File file) {
		if(file !=null && file.exists()){
			if (file.isFile()) {
				file.delete();
			} else {
				File[] files = file.listFiles();
				for (int i = 0; i < files.length; i++) {
					deleteAll(files[i]);
					files[i].delete();
				}
//				if (file.exists()) // 如果文件本身就是目录 ,就要删除目录
//					file.delete();
			}
		}
	
	}
	
	public static void main(String[] args) {
		MetrialUtil.deleteAll(new File("C:\\file"));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy