When writing files with Chinese characters, it is easy to have garbled characters. Usually the files obtained are usually in "iso8859-1" format and need to be converted to "UTF-8" format. .
For example: String str = new String (str.getByte("iso8859-1"), "UTF-8"); just perform forced conversion and then store it.
Note: Usually the formats are GBK, UTf-8, iso8859-1, and GB2312. If the above forced conversion is unsuccessful, try these formats in sequence and the problem will definitely be solved.
PHP Chinese website has a large number of free JAVA introductory tutorials, everyone is welcome to learn!
The above is the detailed content of How to solve garbled characters when writing files in java. For more information, please follow other related articles on the PHP Chinese website!