代码如下(简略版): private string name; private static font font; private final static byte enter_1 = (byte) 0x0d; //utf-8编码中换行字节1 private final static byte enter_2 = (byte) 0x0a; //utf-8编码中换行字节2 private static datainputstream dis; private static string[] strtxt; //类构造器,我的类名叫explorerscreen public explorerscreen(string name) { setfullscreenmode(true); //全屏 font = font.getdefaultfont(); this.name = name + ".txt"; //合并文件名 dis = new datainputstream(getclass().getresourceasstream(this.name)); strtxt = readtextutf8(dis); //读 addcommand(new command("返回", command.back, 1)); setcommandlistener(this); } public void paint(graphics g) { clearscreen(g); //清屏 drawbackgroup(g); //画背景 g.setcolor(redfont, greenfont, bluefont); //设置字体颜色 //打印文字 for (int i = 0, y = 0; i < strtxt.length; ++i) { g.drawstring(strtxt[i], 0, y, graphics.top | graphics.left); y += font.stringwidth("中"); } } public static string[] readtextutf8(datainputstream dis) { //实际的行数 int m = 0 ; //读取的总byte数 int total = 0; //存放字符串数组开始下标 int itmp = 0 ; //存放字符串数组的byte长度 int len = 0 ; //要跳3个字节,因为前3个字节是utf-8特有的标记 try { dis.skip(3); } catch (ioexception e1) { // todo auto-generated catch block e1.printstacktrace(); } byte[] b = new byte[1024]; //读缓冲 try { total = dis.read(b); //得到读了多少字节 system.out.println("total = " + total); } catch (ioexception e) { // todo auto-generated catch block system.out.println("total = dis.read(b);"); } for (int i = 0; i < total; ++i) { //判断有多少行 if (enter_1 == b[i] && enter_2 == b[i + 1]) { m++; } } string[] s = new string[m]; //建立结果数组,以行数为维数。 for (int i = 0, z = 0; i < total; i++) { //继续判断是否有空格,但这次是为了分行 if (enter_1 == b[i] && enter_2 == b[i + 1]) { len = i - itmp; //得到长度 try { s[z] = new string(b, itmp, len, "utf-8"); //转换并保存结果 } catch (unsupportedencodingexception e) { // todo auto-generated catch block system.out.println("(s[z] = new string"); } itmp = i + 2; //后跳2个字节,因为那是换行符 if (z < s.length) { z++; } } } return s; //返回结果 }
详细解决方案
相关解决方案
- J2ME 改变字体大小解决办法
- j2me 验证码提交,该怎么解决
- j2me 环境筹建
- j2me 怎么获取当月的天数!
- j2me 排序步骤 整数数组
- Effective J2ME(一)
- Effective J2ME(三)
- J2ME Mobile 3D入门教程(2)
- fedora 上 j2me 的 中文 乱码
- j2me 排雷游戏
- j2me 后台老板运行
- 鸟哥,j2me,D608一些有关问题
- Effective J2ME (一)
- Effective J2ME (三)
- Effective J2ME(二)
- J2ME 控制台中文输出乱码有关问题解决
- Effective J2ME(四)
- J2me drawRGB的运用详细解释
- J2ME Mobile 3D入门教程(3)碰撞初步
- 索尼爱立顺手机在 J2ME 程序中的字体大小
- J2ME: 由用户自行设立键值
- J2ME 施用的字体 Font 类
- j2me 验证码交付
- J2me 游戏点阵字库发动机(三)之字体绘制改进算法
- J2me 游戏点阵字库发动机(二)字体绘制函数分析
- J2me 游戏点阵字库发动机(五)之部分汉字库
- J2ME 改变字体大小,该怎么处理
- J2ME android之间的有关问题
- j2me socket联网出有关问题
- J2ME 打包有关问题