Home > Java > JavaBase > body text

How to avoid reading garbled files in java

Release: 2019-12-04 15:46:09
Original
2673 people have browsed it

How to avoid reading garbled files in java

Sometimes when we read a file, we switch between utf-8, gbk, and gb2312 encoding methods, but the code is still garbled. At this time, we need to check the encoding method of the file: (Recommended: java video tutorial)

1. You can directly view the file encoding in Vim

:set fileencoding
Copy after login

2. View the file encoding in subline

The default setting of Sublime Text is not to enable display encoding. If you want to enable it, you can use the menu Perference → Settings – User. In the open configuration file, after the curly brackets, add the following content:

// Display file encoding in the status bar
"show_encoding": true,
// Display line endings in the status bar
"show_line_endings": true,
Copy after login

and then use The encoding method of the file is used to read the file so that it will not be garbled.

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-16LE"));
Copy after login

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of How to avoid reading garbled files in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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