java 用類加載器的方式管理資源和配置文件

public class ReflectTest {
public static void main(String[] args) throws Exception {
    //config.properties 與當前類在不一樣包下;
    InputStream is=ReflectTest.class.getResourceAsStream("/com/jhon/copy/config.properties");
    //在同一個包下
    //InputStream is=ReflectTest.class.getResourceAsStream("config.properties");
    Properties p=new Properties();
    p.load(is);
    is.close();
    String name=p.getProperty("配置字段");
    System.out.println(name);
    }
}spa

相關文章
相關標籤/搜索