/**
	 * 
	 * @param file 上传的文件
	 * @param filePath 上传到那个目录
	 * @return 上传后的文件名字
	 * @throws IOException
	 */
	public static String uploadFileToPath( MultipartFile file, String filePath) throws IOException {
		//获取图片原始名称  1.jpg
        String originalFilename = file.getOriginalFilename();
        //图片扩展名  jsp
        int lastIndexOf = originalFilename.lastIndexOf(".");
        //String types = originalFilename.substring(originalFilename.lastIndexOf(".")+1).toLowerCase();
        String newFileName = "";
        if(lastIndexOf != -1) {
        	newFileName = new Date().getTime() + originalFilename.substring(lastIndexOf);
        }else {
        	newFileName = new Date().getTime() + ".tmp";
        }
        
        String fullPath = filePath + newFileName;
		
		// 创建文件夹
		File dirPath = new File(filePath);
		if (!dirPath.exists() || (!dirPath.isDirectory())) {
			dirPath.mkdirs();
		}
		//创建文件
		File uploadFile = new File(fullPath);
		//Copy文件
		FileCopyUtils.copy(file.getBytes(), uploadFile);
		  
		return newFileName;
	}

  

相关文章:

  • 2021-09-21
  • 2021-11-22
  • 2021-06-26
  • 2021-04-15
  • 2022-01-04
  • 2021-04-17
  • 2021-07-28
  • 2021-07-04
猜你喜欢
  • 2022-02-12
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案