我想支持屬性文件格式,像下面(允許引號包圍值):Java屬性類實現處理雙/單引號值?
key1=value1
key2="value2"
key3='value'
我的問題是 做Java屬性類實現處理類似上面的雙/單引號值?我的意思是自動刪除引號。
其實我試過的不是,只是想在這裏確認。所以我必須自己刪除引號。
編輯:
我爲我的簡單情況如下代碼:
String path = "/tmp/my.properties";
Properties p = new Properties();
p.load(new FileInputStream(new File(path)));
String v = p.getProperty("key2");
if((v.startsWith("\"") && v.endsWith("\"")) ||
(v.startsWith("\'") && v.endsWith("\'"))) {
v = v.substring(1, v.length()-1);
}
最佳實踐任何建議來處理呢?
感謝
http://stackoverflow.com/questions/2406975/how-to-escape-the-equals-sign-in-properties-files –
很好的參考,但不完全是我要求的 – Eric