標籤:public IV config inpu 伺服器ip nts ror style ddr
直接上代碼:
package com.base.jet.utils;import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class PropertiesUtils { private Properties properties; private static PropertiesUtils propertiesUtils = new PropertiesUtils(); //私人構造,禁止直接建立 private PropertiesUtils() { properties = new Properties(); InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream("config.properties"); try { properties.load(in); } catch (IOException e) { e.printStackTrace(); } } //擷取單例 public static PropertiesUtils getInstance() { if (propertiesUtils == null) { propertiesUtils = new PropertiesUtils(); } return propertiesUtils; } //伺服器ip public String getServerIpAddress() { return properties.getProperty("server.ipAddress"); } //伺服器連接埠 public String getServerPort() { return properties.getProperty("server.Port"); } //是否是偵錯模式 public Boolean getServerIsDebug() { return properties.getProperty("server.isDebug").equals("1"); } //密碼最大錯誤次數 public int getPwdRrrorCounts() { return Integer.parseInt(properties.getProperty("user.pwdRrrorCounts")); } //系統版本號碼 public String getSysVersion() { return properties.getProperty("sys.version"); } public static void main(String[] args) { PropertiesUtils pro = PropertiesUtils.getInstance(); System.out.println("http://" + pro.getServerIpAddress() + ":" + pro.getServerPort() + "/"); }}
java 讀取properties設定檔