随时间动态创建文件夹

想到以后要讲图片随着每天存储到不同的文件夹,就想着创建一个跟随日期的文件夹的方法,为自己以后的毕设做准备,以下是方法:
import java.util.Date;
import java.text.SimpleDateFormat;
class file{
    final static String way="C:\\Users\\****\\Desktop\\";
    static File file1=null;
    static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
    static String time=df.format(new Date()).replaceAll("-","");// new Date()为获取当前系统时间
    public static String filexits(){
        String msg=null;
        file1=new File(way+time);
        if(!file1.exists()){
            file1.mkdirs();
            msg="创建成功";
        }else{
            msg="文件已存在";
        }
        return way+time;
    }
}

 

posted @ 2019-11-18 17:51  学习就是进步!  阅读(422)  评论(0)    收藏  举报