@GetMapping("preview1")@ApiOperation(value = "根据文件名实现预览功能")public void previewFile1( HttpServletResponse response) throws IOException {String filePath="C:\\Users\\Harbor Lau\\Desktop\\哈哈\\"+"11月燃油费(公开).pdf";InputStream in = new BufferedInputStream(new FileInputStream(filePath));//加上就是只能预览pdf啦,一般直接注释掉就行//response.setContentType("application/pdf;charset=UTF-8");OutputStream outputStream = response.getOutputStream();//创建存放文件内容的数组byte[] buff = new byte[1024];//所读取的内容使用n来接收int n;//当没有读取完时,继续读取,循环while ((n = in.read(buff)) != -1) {//将字节数组的数据全部写入到输出流中outputStream.write(buff, 0, n);}//强制将缓存区的数据进行输出outputStream.flush();//关流outputStream.close();in.close();}