java创建文件夹的坑

        SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd");//设置日期格式
        String date = df.format(new Date());
        String path = request.getSession().getServletContext().getRealPath("/");
        System.out.println(path);

        path = path.concat("uplader/");
        File fileParent = new File(path);

        path = path.concat(date+'/');
        System.out.println(path);

        file = new File(path);
        if(!fileParent.exists()){
            fileParent.mkdirs();
        }

        if (!file.exists()) {
            file.mkdir();
        }

二话不说先上代码

这个file.mkdir()只能创建一级文件夹 所以咯~~~

先获取一层的路径 创建 反复即可

猜你喜欢

转载自blog.csdn.net/b_e_w/article/details/89437886