我試圖設置我的數據庫屬性,所以在將來用戶可以更改它,如果他們想要更改數據庫的路由。問題是當我嘗試設置全角冒號時,它總是添加一個反斜槓轉義字符。在Java中輸入全角冒號(:)到setProperty
我試過正常和雙重轉義,但它不起作用。
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
public class SetProps {
public static void SetDefaultProps(){
Properties prop = new Properties();
OutputStream output = null;
try {
output = new FileOutputStream("./build/classes/configuracion.properties");
// Set the database property
prop.setProperty("url", "jdbc:mysql://192.168.1.192:3306/ordenestaller");
// Save Properties
prop.store(output, null);
} catch (IOException io) {
io.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
SetDefaultProps();
}
}
你不需要逃脫在MySQL網址什麼,冒號是一個普通的字符 –
功能的setProperty隨時添加到:反斜槓/: –
IST是不是「setProperty' - 方法。這是'商店'的方法,將添加// – Jens