myeclipse寫配置文件,在程序裏找到路徑,並讀取配置文件的內容

寫配置文件,在程序裏找到路徑,並讀取配置文件的內容:
String classPath = this.getClass().getClassLoader().getResource("/").getPath(); //得到當前路徑
FileInputStream fin = new FileInputStream(classPath+"portconfig");//讀取配置文件路徑,portconfig爲文件名
Properties pr = new Properties();
pr = new Properties();
pr.load(fin);
ServicePort = pr.getProperty("SERVICEPORT"); //讀取參數,ServicePort 參數
fin.close();
pr = null;
fin = null;

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