首页 > 编程语言 > 详细

java上传文件

时间:2017-10-27 11:10:41      阅读:186      评论:0      收藏:0      [点我收藏+]
public void upload(MultipartFile file, String saveurl,String showurl,) throws Exception {
try {
            String suffix = file.getOriginalFilename().substring(  //文件后缀
            file.getOriginalFilename().lastIndexOf(".") + 1);
            File destFile = new File(saveurl);
            if (!destFile.exists()) {
                destFile.mkdirs();
            }
            String fileNameNew = getFileNameNew() + "." + suffix;//新的文件名
            File f = new File(destFile.getAbsoluteFile() + "/" + fileNameNew);//保存路径
        f.createNewFile();
file.transferTo(f); // fileName = basePath + destDir + fileNameNew;
fileName = saveurl + fileNameNew;
   oldfileName
= file.getOriginalFilename();
       newfileName
= fileNameNew;
}

catch (Exception e) { throw e; }
}

 

java上传文件

原文:http://www.cnblogs.com/syscn/p/7742011.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!