Solution:
1. First, set the encoding format of the text file to be read to UTF-8;
2. Use the InputStreamReader class Read the file, because the character set can be specified in its construction method, and its character set is specified as UFT-8 format.
Example:
BufferedReader buff = new BufferedReader(new InputStreamReader(new FileInputStream("test.txt"),"UTF-8"))
Using the BufferedReader class is to use the readLine() method in this class.
Recommended tutorial: Java tutorial
The above is the detailed content of Solution to garbled characters when reading text files in Java. For more information, please follow other related articles on the PHP Chinese website!