Java read a text file without quote marks

374 Views Asked by At

Text file is like

"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);
}

I want to display

Name Salary Bernard 200000.00

2

There are 2 best solutions below

2
On BEST ANSWER

The Regex method for this would be to use

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

to replace each "," with a space.

0
On

Something like splitValue.replace("\"", "")

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

You will also want to add a space instead of empty string here (not sure if it's a typo):

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