How to replace double quotes in headers and rows in a CSV file in Java

I am new to Java. I have the following CSV file located in my local folder: C:\Users\MyFile\myFile.csv. The first line of the file is the header. I would like to replace the double quotes from headers and values in the file and replace the file in the same location. I used this code how to remove double quotes while reading CSV to mimic the logic, but couldn’t succeed. 

Actual myFile.csv (sample records):


Expected myFile.csv (sample records):


>Solution :

Read the contents, remove quotes, write back:

String contents = new String(Files.readAllBytes(Paths.get(fileName)));
contents = contents.replace("\"", "");
Files.write(Paths.get(fileName), contents.getBytes());

Leave a Reply