亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

屬性文件駐留在Java應用程序之外引發fFileNotFoundException

屬性文件駐留在Java應用程序之外引發fFileNotFoundException

慕絲7291255 2021-04-16 15:14:39
由于某種原因,我必須將*.properties文件放置在Java應用程序之外。當文件km.properties駐留在java/src/resources/km.properties代碼中時,將讀取文件,但是當我將同一文件放入C:\Users\abc\Desktop\km.properties 其中時,將拋出Exception: java.io.FileNotFoundException: property file 'C:\Users\abc\Desktop\km.properties' not found in the classpathException in thread "main" java.lang.NullPointerException    at com.ir.Constants.<init>(Constants.java:44)    at com.Constants.main(Constants.java:64)這是我的代碼public class Constants {    public Constants(){        System.out.println(System.getenv("km_config"));        try {            Properties prop = new Properties();            String propFileName = System.getenv("km_config");            inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);            if (inputStream != null) {                prop.load(inputStream);            } else {                throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");            }        }        catch (IOException e) {            System.out.println("Exception: " + e);        }        catch (Exception e) {            System.out.println("Exception: " + e);        } finally {            try {                inputStream.close();            } catch (IOException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }        }    }public static void main(String[] args) throws Exception {        Constants c = new Constants();         System.out.println(Constants.DB_PATH1);         System.out.println(Constants.GIT_REPO_PATH);         System.out.println(Constants.GIT_MAIN_BRANCH_NAME);         System.out.println(Constants.TAGGER_PATH);    }Constants.java:44 是inputStream.close();Constants.java:64 是常量c =新的Constants();請幫助我,我需要將km.properies文件放置在Java應用程序之外的任何位置命令結果echo %km_config%C:\Users\abc\Desktop\km.properties
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號