Java 读取不带引号的文本文件

Java read a text file without quote marks

文本文件就像

"Name","Salary", "Bernard,"200000.00"

BufferedReader br = new BufferedReader(new FileReader("file.txt"));
String line = br.readLine();
String[] splitLine = line.toString().split(",");
for (String splitValue: splitLine) { 
    System.out.println(""+splitValue);
}

我要展示

Name Salary Bernard 200000.00

类似于 splitValue.replace("\"", "")

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace(java.lang.CharSequence,%20java.lang.CharSequence)

您还需要在此处添加 space 而不是空字符串(不确定是否打字错误):

System.out.println(""+splitValue);

Regex 方法是使用

str.replaceAll("\",\"", " ");

将每个 "," 替换为 space。