标签:上传文件
函数:
//文件上传用的函数
protected String saveUploadFile(File upload) {
//1,得到文件上传的文件夹的真实路径
String basePath = ServletActionContext.getServletContext().getRealPath("/WEB-INF/upload_files");
SimpleDateFormat sdf=new SimpleDateFormat("/yyyy/MM/dd/");
String datePath = sdf.format(new Date());
//2,如果文件不存在就创建
File dir=new File(basePath+datePath);
if(!dir.exists()){
dir.mkdirs();
}
String path=basePath+datePath+UUID.randomUUID().toString();//文件后缀名可以不加,因为并不影响这个文件
File destFile=new File(path);
//3,移动文件
upload.renameTo(destFile);
return path;
}标签:上传文件
原文地址:http://blog.csdn.net/u014010769/article/details/46006575