-2

文本文件就像

"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

4

2 回答 2

2

Regex方法是使用

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

","用空格替换每个。

于 2018-06-21T18:28:59.420 回答
0

像 splitValue.replace("\"", "")

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

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

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

于 2018-06-21T18:27:17.880 回答