//commons-fileupload-1.2.1.jar
public static String upload(File file, String fileName, String realpath) {
String fileType = fileName.substring(fileName.lastIndexOf("."),
fileName.length());
//文件重命名规则
String imageFileName = serial();
if (file != null) {
File savefile = new File(new File(realpath), imageFileName
+ fileType);
if (!savefile.getParentFile().exists()) {
savefile.getParentFile().mkdirs();
}
try {
FileUtils.copyFile(file, savefile);
return imageFileName+ fileType;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
return null;
}