Home  >  Article  >  Java  >  How to avoid reading garbled files in java

How to avoid reading garbled files in java

尚
Original
2019-12-04 15:46:092615browse

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

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,

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"));

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!

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