1. gzyueqian
      18529173453
      首頁 > 新聞中心 > > 正文

      J2ME中讀取Unicode和UTF-8編碼文件

      更新時間: 2007-06-04 10:10:14來源: 粵嵌教育瀏覽量:795


      一、讀取Unicode文件

      /**

      * 讀取Unicode編碼文本文件

      * @param resource String - 文件名

      * @return String - Unicode文本

      */

      public static String read_Uni(String resource) {

      byte word_uni[] = new byte[1024];

      String strReturn = null;

      InputStream is;

      try {

      is = instance.getClass().getResourceAsStream(resource);

      is.skip(2); // 跳過兩個字節的文件頭

      is.read(word_uni);

      is.close();

      StringBuffer stringbuffer = new StringBuffer("");

      for (int j = 0; j < word_uni.length; ) {

      int l = word_uni[j++];

      int h = word_uni[j++];

      char c = (char) ((l & 0xff) | ((h << 8) & 0xff00));

      stringbuffer.append(c);

      }

      strReturn = stringbuffer.toString();

      } catch (IOException ex) {

      System.out.println(ex);

      } finally {

      is = null;

      }

      return strReturn;

      }

      二、讀取UTF-8文件

      /**

      * 讀取UTF-8編碼文本文件

      * @param resource String - 文件名

      * @return String - UTF-8文本

      */

      public static String read_UTF(String resource) {

      byte word_utf[] = new byte[1024];

      String strReturn = null;

      InputStream is;

      try {

      is = instance.getClass().getResourceAsStream(resource);

      is.read(word_utf);

      is.close();

      strReturn = new String(word_utf, "UTF-8");

      } catch (IOException ex) {

      System.out.println(ex);

      }

      return strReturn;

      }

      免費預約試聽課

      亚洲另类欧美综合久久图片区_亚洲中文字幕日产无码2020_欧美日本一区二区三区桃色视频_亚洲AⅤ天堂一区二区三区

      
      

      1. 小说区图片区综合久久亚洲 | 日韩精品成人区中文字幕 | 亚洲欧美日韩国产另类丝瓜 | 久久综合丝袜日本网首页 | 午夜精品亚洲一级在线 | 夜色福利院在线观看免费 |