在方法裡面建立properties對象 Properties pps = new Properties(); 調用.load()方法 pps.load(new FileInputStream("E:\\workplace\\testStudent\\src\\we.properties")); 整個 ...
在方法裡面建立properties對象 Properties pps = new Properties(); 調用.load()方法 pps.load(new FileInputStream("E:\\workplace\\testStudent\\src\\we.properties")); 整個方法 public static String getValueByKey(String key){ Properties pps = new Properties(); try { pps.load(new FileInputStream("E:\\workplace\\testStudent\\src\\we.properties")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return (String)pps.get(key); 建立main方法測試 public static void main(String[] args) { int a=0; String category=Constant.getValueByKey("UIConfig.category"); String[] categoryvalue = category.split("\\|"); for (String str : categoryvalue) { String[] test = str.split("\\:"); System.out.println(test[1]); System.out.println(test[0]); } }