How to write a UTF-8 file with Java?

前端 未结 9 1267
半阙折子戏
半阙折子戏 2020-11-22 16:17

I have some current code and the problem is its creating a 1252 codepage file, i want to force it to create a UTF-8 file

Can anyone help me with this code, as i say

9条回答
  •  旧时难觅i
    2020-11-22 17:02

    Try using FileUtils.write from Apache Commons.

    You should be able to do something like:

    File f = new File("output.txt"); 
    FileUtils.writeStringToFile(f, document.outerHtml(), "UTF-8");
    

    This will create the file if it does not exist.

提交回复
热议问题