How to read a file in Java with specific character encoding?

后端 未结 3 1260
别跟我提以往
别跟我提以往 2020-12-09 16:14

I am trying to read a file in as either UTF-8 or Windows-1252 depending on the output of this method:

public Charset getCorrectCharsetToApply() {
    // Retu         


        
3条回答
  •  长情又很酷
    2020-12-09 16:46

    With Java 7+, you can create the Reader in one line:

    BufferedReader buffReader = Files.newBufferedReader(Paths.get(fileName), getCorrectCharsetToApply());

提交回复
热议问题