0
私はpdfファイルを開いて、クライアントのデスクトップに表示しようとしています。 Tomcatサーバーでjavaを使用しています。 ファイルはプロジェクトのresourcesフォルダーにあり、ビルド後はWEB-INF/resources/in.pdfJava:inputStream = null PDFファイルからnull
nullが返されます。どのようにしてファイルの実際のパスを見つけることができますか?ここ
コードです:
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();
}
http://stackoverflow.com/questions/1108434/howto-load-a-resource-from-web-inf-directory-of-a-web-archive ... try 'getResourceAsStream(" WEB-INF/resources/in.pdf ")' – Tom
ありがとう、それは動作します:) –