java get request to accept the problem when downloading files with the Chinese

The argument is received, debug, they also can see that, but the strange thing is I could not find the file

@ApiOperation(value = "文件下载/图片预览")
	@GetMapping(value = "/file/{type:download|view}")
	public Object fileDownloadOrView(ModelMap modelMap,String filePath,String fileName,@PathVariable ("type") String type,
			HttpServletResponse responsen ) throws Exception {
		if(StringUtils.isBlank(filePath)){
			modelMap.put("msg", "参数错误!!!");
			return setModelMap(modelMap, HttpCode.BAD_REQUEST);
		}
		String note=new String(filePath.trim().getBytes("ISO-8859-1"), "UTF-8");
		File file = new File(note);
		if(file.exists() && file.isFile()){
			if("download".equals(type)){
				String fileSuffix  = file.getName().substring(file.getName().lastIndexOf("."),file.getName().length());
				if(StringUtils.isEmpty(fileName)){
					fileName = UUID.randomUUID().toString();
				} 
				fileName = fileName+fileSuffix;
				try {
					responsen.setContentType("multipart/form-data");   
					responsen.addHeader("Content-Length", "" + file.length());
					responsen.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
				} catch (UnsupportedEncodingException e1) {
					e1.printStackTrace();
				}
			}
			
			FileInputStream inputStream = null;
			OutputStream outputStream = null;
			try {
				 inputStream = new FileInputStream(file);
				 outputStream = responsen.getOutputStream();
				 IOUtils.copy(inputStream, outputStream);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					inputStream.close();
					outputStream.flush();
					outputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return null;
		} else {
			modelMap.put("msg", "文件不存在!!!");
			return setModelMap(modelMap, HttpCode.CONFLICT);
		}
	}

  I do not know why, but 

String note=new String(filePath.trim().getBytes("ISO-8859-1"), "UTF-8");
File file = new File (note) ; 
so it really transformed the Road King on the line

Guess you like

Origin www.cnblogs.com/sunjinggege/p/11226664.html