Reliance on default encoding, what should I use and why?

前端 未结 4 1760
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-28 14:36

FindBugs reports a bug:

Reliance on default encoding Found a call to a method which will perform a byte to String (or String to byte) conversion, a

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-28 15:01

    When you are using a PrintWriter,

    File file = new File(file_path);
    Writer w = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_16.name());
    PrintWriter pw = new PrintWriter(w);
    pw.println(content_to_write);
    pw.close();
    

提交回复
热议问题