81,091
社区成员
发帖
与我相关
我的任务
分享
//取出当天的日期,转换成字符串
String date = ...
//savePath :存放路径,一般上传目录的根目录都是配置的.此处假定一个目录
String savePath ="/app/upload";
savePath = savePath + File.separator + date;
//创建文件,如果不传在创建所有层次的目录
File dirFile = new File(savePath);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
//将文件重新命名,存放到指定目录 reName: 新的文件名 fileext:文件扩展名
targetPath = savePath + File.separator + reName + "." + fileext;
File targetfile = new File(targetPath);
//save file ,此处使用的是apache的通用上传包
item.write(targetfile);
//remove temp file
item.delete();