J2ME中读取Unicode和UTF-8编码文件
来源:互联网 发布:淘宝免费开店注册不了 编辑:程序博客网 时间:2024/06/06 05:06
一、读取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;
}
- J2ME中读取Unicode和UTF-8编码文件
- J2ME中读取Unicode和UTF-8编码文件
- J2ME中读取Unicode和UTF-8编码文件
- J2ME中读取Unicode和UTF-8编码文件
- J2ME中读取Unicode和UTF-8编码文件
- J2ME中读取Unicode和UTF-8编码文件
- J2ME中读取Unicode和UTF-8编码文件的方法
- J2ME读取UTF-8编码文件方法
- J2ME读取UTF-8编码文件方法
- J2ME读取本地文本文件(ANSI,Unicode,Unicode big endian,UTF-8编码)
- python中编码unicode和utf-8
- unicode和UTF-8编码
- UTF-8编码和UNICODE
- Unicode和UTF-8编码
- Unicode编码:UTF-8和UTF-16
- 从utf-8文件中读取转换成unicode
- ASCII编码和UNICODE、utf-8编码
- unicode编码和utf-8编码详解
- Nebula2探秘序章:Nebula2环境配置
- Unraveling Bezier Splines
- 上海之行(2)
- Kevin的DirectInput简明教程
- set ansi_nulls [on/off] 与 set quoted_identifier [on/off]
- J2ME中读取Unicode和UTF-8编码文件
- 关于飞机射击类游戏的设计原理 (加入时间:2001-3-4)
- 开源可视化 Python 性能调优工具 VPT 发布
- 游戏人工智能演示(1)追逐
- 接受了 CSDN 的《专家看台》采访
- 游戏人工智能演示(0)框架
- 程序员必知必会之 word 篇
- 用Python做图像处理
- 《时间管理》培训笔记