1. About file encoding general file saving (text file) It is also the reason for the current system default language (character set) encoding, so some Chinese characters will show garbled in Japanese system. It is said that it is to open the file. Different platforms are different, such as Chinese characters. Sets include A, B, C, Japanese character sets including A, B. When decoding Chinese characters C, there will be so-called garbled when the Chinese character C is decoded.
2. Java Work Processing Coding Mode (1) Java will store characters in Unicode in the running period, which is advantageous to support multi-language environments. (2) Java is default the default language according to the system when reading the file (character set) Coding to decode file, read, and save the encoding inconsistencies in the program, also lead to the parameter value in the program, read files with the FileInputStream class, can specify the encoding reading (3) Java When output to the system interface (Windows) The character is then encoded by the system default language (character set), so a series of encoding problems will also be encountered during the output.
3. Solution (1) SWING / AWT: Output to the system interface decoding can replace the system character set to decode, for example: public static void setfont ("Button.Font", PFONT); UIManager.Put ("ToggleButton.font", PFont); UIManager.Put ("Radiobutton.Font", PFont; UIManager.put ("Checkbox.Font", PFont; uimanager.put ("Colorchooser.font ", PFONT); UIManager.Put (" ToggleButton.font ", PFont); UIManager.Put (" ComboBox.Font ", UIManager.put (" ComboBoxItem.Font ", PFont); UIManager.put (" InternalFrame .titlefont ", pfont); UIManager.put (" Label.Font ", PFont); UIManager.put (" List.Font ", PFont); UIManager.put (" MenuBar.font ", PFont); UIManager.put "Menu.font", pfont; uimanager.put ("MenuItem.font", PFont; UIManager.Put ("RadiobuttonMenuItem.font", PFont); UIManager.Put ("CheckBoxMenuItem.Font", PFont; UIManager. PUT ("Popupmenu.Font", PFont; UIManager.Put ("optionpane.font", pfont; uimanager.put ("Panel.Font", PFont; UIManager.put ("ProgressBar.font", PFont; UIManager.put ("scrollpane.font", pfont; uimanager.put ("Viewport" , pfont; uimanager.put ("tabbedpane.font", pfont); UIManager.put ("TableHeader.Font", PFont; UIManager.put ("Table.Font", PFont; UIManager.put ("TextField. Font ", pfont); UIManager.put (" passwordfiled.font ", pfont; uimanager.put (" textarea.font ", pfont); uimanager.put (" textpane.font ", pfont; uimanager.put (" EditorPane.Font ", PFont); UIManager.Put (" Titledborder.Font ", PFont); UIManager.put (" Toolbar.Font ", PFont); UIManager.put (" Tooltip.Font ", PFont);
UIManager.put ("Tree.Font", PFont);} Control software output character set by passing a font name, avoiding garbled 2. JSP: You can solve the CHARSET to solve the problem, for example: <% @ page contenttype = "Text / html; charSet = GB2312 "%>
3. Database: Java also generates encoding problems in the database stream, and can refer to the method of the file, decoding at a specific character set while receiving the stream, for example: use method InputStreamReader (InputStream in, charset cs) can be implemented