String path = request.getServletContext().getRealPath("upload") + File.separator;
//形成年月日的文件夾, 下面每天一個(gè)文件夾
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
String uploadDir = year + "" + month + File.separator + day;
File uploads = new File(path + uploadDir);
if (!uploads.exists()) {uploads.mkdirs();} //注意這里是mkdirs,不是mkdir
//生成目錄結(jié)束JAVA創(chuàng)建多級(jí)目錄
- 位置:
- 雅騰科技 >
- 常見(jiàn)問(wèn)題 >
- JAVA >
- 正文
