一、查看文件
@RestController
public class PDFController {
@RequestMapping(value = {"/web/pdf"})
public void download(HttpServletResponse response) throws Exception {
FileInputStream is = new FileInputStream(new File("C:\\*", "*.pdf"));
// attachent : 下载; inline : 查看
response.setHeader("content-disposition", "inline;fileName=" + URLEncoder.encode("*.pdf", "UTF-8"));
ServletOutputStream os = response.getOutputStream();
IOUtils.copy(is, os);
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
二、下载文件
@RestController
public class PDFController {
@RequestMapping(value = {"/web/pdf"})
public void download(HttpServletResponse response) throws Exception {
FileInputStream is = new FileInputStream(new File("C:\\*", "*.pdf"));
// attachent : 下载; inline : 查看
response.setHeader("content-disposition", "attachent;fileName=" + URLEncoder.encode("*.pdf", "UTF-8"));
ServletOutputStream os = response.getOutputStream();
IOUtils.copy(is, os);
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
三、上传文件
@RequestMapping(value = {"/web/upload"})
public String upload(@RequestBody MultipartFile file) throws Exception {
File filePath = new File("C:\\path", "*.pdf");
if(!filePath.exists()){
filePath.mkdirs();
}
file.transferTo(filePath);
return "上传成功";
}
网友评论