Home  >  Article  >  Java  >  Solution to garbled characters when reading text files in Java

Solution to garbled characters when reading text files in Java

王林
王林Original
2019-11-13 14:47:403117browse

Solution to garbled characters when reading text files in Java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn