我有一个文本文件,其中包含很多行,我需要从该行中找到一个特定的“单词”,删除双引号并将其打印到文本字段中。
@FXML
private void findCFG(ActionEvent event) throws FileNotFoundException, IOException {
FileChooser fc = new FileChooser();
fc.setTitle("Open cfg file");
File cfgName = fc.showOpenDialog(null);
cfgPathLabel.setText(cfgName.getPath());
Scanner sc = new Scanner(cfgName);
while (sc.hasNextLine()) {
String word = sc.nextLine();
if (word.startsWith("volume ")) {
String[] splitter = word.split("volume ");
for (String s : splitter) {
volField.appendText(s);
}
}
}
}
我的结果
"0.1"
我想要的结果是
0.1
如果要删除所有双引号,则可以使用以下代码:
string=string.replaceAll("\"", "");
您将所有双引号替换为空。将变量字符串用作带双引号的字符串。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句