Java之递归删除文件与获取前几天日期方法

1.最近做项目要用到这两个方法就一起贴代码到这了:

public class DelfileUtils {

	public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
        	//获取子目录
            String[] children = dir.list();
            //递归删除目录中的子目录下文件
            for (int i=0; i<children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }
        // 目录此时为空,可以删除
        return dir.delete();
    }
	
	//获取几天前日期
	public static String delName() {
		//周期
		int day = configuration.getInt("log.delDate");
		//取时间
		Date date=new Date();  
		Calendar calendar = new GregorianCalendar();  
		calendar.setTime(date); 
		//把日期往后增加一天.整数往后推,负数往前移动
		calendar.add(calendar.DATE,-day);
		//这个时间就是日期往后推一天的结果
		date=calendar.getTime();    
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");  
		String dateString = formatter.format(date);
		return dateString;
    }
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值