1、getResourceAsStream(String path)讀取的文件路徑是與工程相關的,例如工程中的某個路徑下的文件(/demo/static/img/logo.png)。
2、如果文件不在工程目錄下,應該採用以下方式:
File file = new File(logoPath); InputStream is= null; try{ is = new FileInputStream(file); }catch (Exception e){ e.printStackTrace(); }
3、本篇文章主要是記錄getResourceAsStream(String path)的用法,如有錯誤,請糾正。