我想打開一個圖像文件,打包在一個.jar文件中,使用我運行程序的計算機的默認圖像查看器。從java輸入流打開圖像文件
我發現了很多關於如何訪問使用InputStream打包在一個jar中的文件的答案,但是如何使用該InputStream打開這些文件?
InputStream imageStream = Test.class.getClass().getResourceAsStream("/test/DSC_6283.jpg");
我可以將此轉換爲Image
,ImageIcon
或BufferedImage
但如何我進一步打開默認的圖像瀏覽器的形象呢?
我的類名是「測試」,我試圖訪問的圖像是C:\Users\Pranav\Documents\NetBeansProjects\Test\src\test\DSC_6283.jpg
任何幫助,將不勝感激。
更合適!:)完美的作品!你能解釋一下這些線是如何工作的嗎? 'while((len = imageStream.read(buffer))!= -1)'byte [] buffer = new byte [1024];' 'int len;' ' {' 'out.write(buffer,0,len);' '}' – Pranav 2014-09-06 02:17:11
@Pranav添加評論 – Andreas 2014-09-08 16:02:57
非常感謝! :D @Andreas – Pranav 2014-09-08 16:26:07