I load the text file UTF-8 with letters / numbers using java.io.File . While I run from IDE directly - everything is fine - and reads and writes.

After publishing to jar or exe, they stop understanding UTF, but it works correctly with ANSI. However, an application launched from the IDE does not digest ANSI. Can I explicitly specify the encoding when loading / saving?

PS: Everything happens in the javaFX application, if it matters.

    1 answer 1

    The java.io.File encoding cannot be specified.

    Explicitly specify the encoding, for example, in the InputStreamReader constructor:

     InputStreamReader(InputStream in, String charsetName) 

    and in the OutputStreamWriter constructor:

     OutputStreamWriter(OutputStream out, String charsetName) 

    Example for reading:

     File file = new File("test.txt"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8")); 

    Example for writing:

     File file = new File("test.txt"); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8"));