Search code examples
javatext-filesread-text

Java read a text file without quote marks


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


Solution

  • The Regex method for this would be to use

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

    to replace each "," with a space.