檔案在Java工程和 jar包統一處理
阿新 • • 發佈:2018-11-09
default.ini配置檔案,希望在程式碼開發過程中和打成jar包釋出過程中都能夠讀取到。
File file = new File("default.ini"); InputStream fis; if (file.exists()) { fis = new FileInputStream(file); } else { // 定位jar內資源 fis = this.getClass().getResourceAsStream("/default.ini"); } init(fis);
private void init(InputStream is)
throws Exception
{
Properties config = new Properties();
config.load(is);
// ......
IOUtils.closeQuietly(is);
}