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!