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

Solution to garbled characters when reading text files in Java

王林
Release: 2019-11-13 14:47:40
Original
3224 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!

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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template