private static void createPropertiesFile() {
Properties prop = new Properties();
OutputStream output = null;
try {
output = new FileOutputStream(
"c://properties//xyz.properties");
// set the properties value
prop.setProperty("URL", hostName);
prop.store(output, null);
} catch (IOException io) {
io.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
屬性文件中的示例數據如下所示。如何忽略屬性文件中出現的反斜槓,如:and =
#Tue Oct 06 15:26:55 IST 2015
URL=jdbc\:sqlserver\://abc.xyz.net
我的理解是,任何事情之前先「=」作爲重點和任何處理過的第一後「=」作爲視爲價值。在這個過程中,當遇到像:和=這樣的字符時,它們會被反斜槓'\'轉義。
可當遇到有人請從屬性出現在首位幫助我如何刪除或限制「\」文件:和=
爲什麼?應該使用'Properties'來輕鬆地從文件系統讀寫。如果你想使用輸出文件做別的事情,不要使用'Properties'。 – Manu
我需要在這種情況下使用鍵(即URL)xyz.properties,但有沒有辦法如何處理這與屬性,因爲我的要求是去與屬性文件。 – Raghottam
你是什麼意思?你想要第二個程序(不是Java)來讀取文件並使用鍵值對? – Manu