Home > Java > JavaBase > body text

Solution to garbled characters when reading text files in Java

王林
Release: 2019-11-13 14:47:40
Original
3102 people have browsed it

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"))
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!