I try to open a pdf file and display it on the client's desktop. I use java on a Tomcat server. The file is in the resources folder of the project, and after the build is in WEB-INF/resources/in.pdf
The inputStream returns null, how can i found the real path of the file?
here is the code:
try{
if (Desktop.isDesktopSupported()) {
File file = new File("out.pdf");
if (!file.exists()) {
InputStream inputStream = ClassLoader.getSystemClassLoader()
.getResourceAsStream("/WEB-INF/resources/in.pdf");
OutputStream outputStream = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
outputStream.close();
inputStream.close();
}
Desktop.getDesktop().open(file);
}
}catch(Exception e1)
{
e1.printStackTrace();
}