我的程序需要從多行.ini文件中讀取,我已經知道它讀取以#開頭的每一行並打印它。但我只想記錄=號後的值。這裏的文件應該是什麼樣子:Buffered Reader找到特定的行分隔符char然後讀取該行
#music=true
#Volume=100
#Full-Screen=false
#Update=true
這是我想它打印:
true
100
false
true
這是我的代碼,目前我使用:
@SuppressWarnings("resource")
public void getSettings() {
try {
BufferedReader br = new BufferedReader(new FileReader(new File("FileIO Plug-Ins/Game/game.ini")));
String input = "";
String output = "";
while ((input = br.readLine()) != null) {
String temp = input.trim();
temp = temp.replaceAll("#", "");
temp = temp.replaceAll("[*=]", "");
output += temp + "\n";
}
System.out.println(output);
}catch (IOException ex) {}
}
我m不知道是否replaceAll(「[* =]」,「」);真正意味着什麼,或者只是爲了尋找所有這些字符。任何幫助表示讚賞!
如果僅在一個線程中訪問對象,則使用'StringBuilder'優先於'StringBuffer',否則您將爲效率降低而支付'StringBuffer'的線程安全性。 – neuralmer