ResourceBundle讀取的文件是在classpath路徑下,也就是src或者src目錄下,而咱們在項目中須要打包,打包後的properties文件在jar中,修改很不方便,咱們須要把properties文件放在jar外隨時能夠修改。java
一、通常狀況下ResourceBundel讀取文件方式默認的讀取路徑是classpath,配置文件名爲resourceBundle.properties。在src根目錄下爲:spa
ResourceBundle rb=ResourceBundle.getBundle("resourceBundle")
若是在某包下,則爲:package.resourceBundle,好比在xcc包下:code
ResourceBundle rb=ResourceBundle.getBundle("xcc.resourceBundle")
二、resourceBundle.properties放在一個文件夾下,好比新建config文件夾,xml
private static ResourceBundle rb; private static BufferedInputStream inputStream; static { // rb = ResourceBundle.getBundle("xcc.resourceBundle"); String proFilePath = System.getProperty("user.dir") + "\\config\\resourceBundle.properties"; try { inputStream = new BufferedInputStream(new FileInputStream(proFilePath)); rb = new PropertyResourceBundle(inputStream); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
三、若是須要配置在Spring配置文件中,則能夠參考以下配置:get
<context:property-placeholder location="file:./properties/jdbc.properties" />
這樣打包後能夠直接修改properties文件input