Question:
How to write UTF-8 files in Java?
Background:
The existing code uses FileWriter to create 1252 code page files, which need to be forced to UTF-8 files.
Solution:
Unable to specify encoding when using FileWriter. To create a UTF-8 file, use the following steps:
The following example demonstrates how to do this:
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(PROPERTIES_FILE), StandardCharsets.UTF_8)) { // 写入数据 }
The above is the detailed content of How to Write UTF-8 Files in Java?. For more information, please follow other related articles on the PHP Chinese website!