Search code examples
javacsvutf-8bufferedreaderoracle12c

Open a BufferedReader in UTF-8


I have a csv file with characters like Cité, but after make the insert into the DB, I see this Cit¿

I open the file as a BufferedReader, but I don't know how to do it in UTF-8

BufferedReader br = new BufferedReader(new FileReader(csvFile));

Solution

  • You could explictly use a FileInputStream and an InputStreamReader using StandardCharsets.UTF_8, but it's probably simpler to use Files.newBufferedReader:

    Path path = Paths.get(csvFile);
    try (BufferedReader reader = Files.newBufferedReader(path)) {
        // Use the reader
    }
    

    It's worth getting to know the Files class as it has a bunch of convenience methods like this.