| 网站首页 | 文章中心 | 电子书下载 | 矢量图库 | 视频教程 | 素材下载 | 程序代码下载 | JS代码 | 论坛 | 
龙腾教程网  
常用软件类:
|杀毒安全 |联络聊天 |网络软件 |多媒体类 |系统工具 |图形图像 |系统工具 |应用软件 |行业软件
开发设计类:
|动画制作 |图像处理 |3D设计 |操作系统 |站长学院 |网络相关 |WEB设计 |数据库类 |程序开发
 
  您当前位置:您现在的位置: 龙腾软件教程网 >> 文章中心 >> 应用程序 >> 移动程序开发 >> J2ME教程 >> 文章正文>>>>>> 
J2ME中读取Unicode和UTF-8编码文件
一、读取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;

   }


上一篇:
  • 上一篇文章:
  • 下一篇
  • 下一篇文章: 没有了
  • 收藏此文到百度搜藏 百度搜藏| 新浪VIvi| 365key| Younote| 博采中心| 你好BLOG| 亿友网摘| 和讯网摘|
    相关文章    
    没有相关文章  
     
     
    最新文章
    普通文章 J2ME中读取Unicode和UTF-8编码文最新文章
    普通文章 MAYA制作逼真的云彩最新文章
    普通文章 ASP.NET2.0 超强文本编辑器FCKed最新文章
    普通文章 photoshop 制作漂亮的手机UI界面最新文章
    普通文章 Illustrator绘制青翠欲滴的叶子最新文章
    普通文章 华为MT800路由+映射设置最新文章
    普通文章 Exchange路由组常见问题的解决方最新文章
    普通文章 无线路由器常见的故障现象及其解最新文章
    普通文章 Cisco路由器基本检验和配置命令集最新文章
    普通文章 Cisco 与 Intel路由器的对连配置最新文章
     
    热门文章
    推荐文章 Photoshop绘制逼真绚丽的金鱼
     
     
    设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 

    版权所有2006-2008 龙腾教程网