希望有人能夠提供幫助,我在java中比較新,並試圖解決如何使用properties函數來讀取多個屬性值,而不一定按順序或全部列表,然後將它們放入數組或字符串中,這樣我就可以傳遞給另一個類來執行寫入文件等「內容」。有可能有數百個屬性值,只想挑選我想要的。 我可以得到一個像properties.getProperty(「ip」);並分配到一個字符串,但具有多個按照下面的問題...將多個java屬性值讀入字符串或數組
任何幫助將不勝感激。
Properties properties = new Properties();
try {
properties.load(new FileInputStream(args[0]));
}
catch (IOException e) {
System.out.println("Error - IOException - File not found...");
}
String model = properties.getProperty("model");
String codeLevel = properties.getProperty("codeLvl");
String[] dmdCommand = new String[properties.getProperty("ip")
+ properties.getProperty("rangeS")
+ properties.getProperty("rangeL")
+ properties.getProperty("PhyPG")
+ properties.getProperty("PhyLDEV")
+ properties.getProperty("PhyProc")
+ properties.getProperty("PhyExG")
+ properties.getProperty("PhyExLDEV")
+ properties.getProperty("PhyCMPK")];
如果您需要其他信息或數據樣本,我們樂意提供。 歡呼聲,並提前致謝:)
考慮使用https://docs.oracle.com/javase/7/docs/api/java/util/PropertyResourceBundle.html –