Created
May 9, 2015 03:49
-
-
Save limingzju/6685cae8f7d1333ac9a0 to your computer and use it in GitHub Desktop.
spring return binary file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(value="/pdfmethod", produces="application/pdf") | |
public void pdfMethod(HttpServletRequest request, HttpServletResponse response){ | |
response.setContentType("application/pdf"); | |
InputStream inputStream = null; | |
OutputStream outputStream = null; | |
try{ | |
inputStream = getInputStreamFromYourPdfFile(); | |
outputStream = response.getOutputStream(); | |
IOUtils.copy(inputStream, outputStream); | |
}catch(IOException ioException){ | |
//Do something or propagate up.. | |
}finally{ | |
IOUtils.closeQuietly(inputStream); | |
IOUtils.closeQuietly(outputStream); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment