jsp文件上传

来源:互联网 发布:java线程优先级原理 编辑:程序博客网 时间:2024/06/18 15:41
//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; }


 

原创粉丝点击