java 讀取Properties配置文件

在根目錄下新建一個xxx.Properties 文件。 文件中的內容以鍵值對的形式存在。 如下:

 然後可以在類中這樣來讀取:

public class getPropertiesTool{

    Properties properties = new Properties();

    properties.load(this.getClass().getClassLoader().getResourceAsStream("para.properties"));

    String lambda=properties.getProperty("lambda");

    String p=properties.getProperty("p");

   String q=properties.getProperty("q"); 

   String n=properties.getProperty("n");

   String nsquare=properties.getProperty("nsquare"); 

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章