クラスローダリソースファイルの取得
3079 ワード
- package cn.lxl.servlet;
-
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.util.Properties;
-
- public class Person {
- public void update() throws IOException {
-
- Properties ps1 = new Properties();
- Properties ps2 = new Properties();
-
- // ,
- ps1.load((Person.class.getClassLoader()
- .getResourceAsStream("config.properties")));
-
- String value1 = ps1.getProperty("name");
- System.out.println("ps1-->" + value1);
-
- // ,
- FileInputStream fis = new FileInputStream(Person.class.getClassLoader()
- .getResource("config.properties").getPath());
- ps2.load(fis);
-
- String value2 = ps2.getProperty("name");
- System.out.println("ps2-->" + value2);
-
- }
- }