国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Java 字符編碼問題

2019-11-18 14:43:48
字體:
來源:轉載
供稿:網友

  1.關于文件編碼
一般文件保存(文本文件),在保存的時候按系統默認語言編碼(字符集)保存, 在中文系統上是GBK,英文系統上是ISO8859_1, 日文系統上是MS932. 在打開的時候同樣是按當前系統默認語言(字符集)編碼去解碼,所以一些中文漢字在日文系統上會顯示亂碼的原因就是這個. 說白了也就是打開文件時候不同平臺使用的字符集不同, 例如中文字符集包括 a,b,c, 日文字符集包括a,b,當在日文系統上解碼漢字c的時候,就會出現所謂的亂碼。

2. java工作處理編碼模式
(1)java在運行期一律以unicode來存儲字符,這樣有利的支持了多語言環境.
(2)java在讀取文件的時候默認是按照系統默認語言(字符集)編碼來解碼文件,讀取和保存時候的編碼不一致也導致程序中參數值錯誤,用FileInputStream類讀取文件可以指定編碼讀取
(3)java在輸出到系統界面時(windows)會把內存中變量字符再通過系統默認語言(字符集)編碼去轉換,所以在輸出過程中也會碰到一系列的編碼問題

3.解決方案
(1)swing/awt : 輸出到系統界面解碼時可以通過設置組件顯示字體來替換系統字符集解碼
例如:
public static void setFont(Font pFont){
UIManager.put("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", pFont);
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);
}
通過傳遞一個字體名稱來控制軟件輸出的字符集,避免產生亂碼

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邯郸市| 锡林浩特市| 行唐县| 东乡族自治县| 尚义县| 泗洪县| 昌宁县| 临沭县| 台南市| 应城市| 申扎县| 清水河县| 康乐县| 鄂托克前旗| 阜南县| 卢龙县| 札达县| 兴宁市| 革吉县| 奎屯市| 手游| 垫江县| 株洲市| 太谷县| 大埔区| 香港| 德江县| 雷波县| 永清县| 武安市| 盘锦市| 枣强县| 绥宁县| 恩平市| 龙井市| 漠河县| 永嘉县| 临沭县| 恭城| 金昌市| 简阳市|