HOHO 可以读取中文了.....

package com.RayiDream;

import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
public class DrawData extends Canvas {
 String str;

 public DrawData() {
  str = getTextByUTF("http://127.0.0.1:8088/data.txt");
 }
   //------------绘制数据-------------------------------------------------------
 protected void paint(Graphics g) {
  System.out.println("22222");
  g.setColor(0xFFFFFF);
  g.fillRect(0, 0, getWidth(), getHeight());//清屏
  g.setColor(0xFF0000);
  g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
    Font.SIZE_LARGE));
  g.drawString(str, getWidth() / 2, getHeight() / 2, Graphics.TOP   //绘制
    | Graphics.HCENTER);
 }
 //-----------读取数据-------------------------------------------------------
 public String getTextByUTF(String url) {
  String strReturn = "";
  int ic;
  InputStream in = null;
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(baos);
  byte[] myData;
  byte[] buffer = new byte[1024];
  try {
   HttpConnection c = (HttpConnection) Connector.open(url);
   in = c.openInputStream();
   if (in != null) {
    while ((ic = in.read(buffer)) > 0) {
     dos.write(buffer, 0, ic);
    }
    myData = baos.toByteArray();
    strReturn = new String(myData);
    in.close();
   }
   dos.close();
   baos.close();
  } catch (Exception e) {
   System.out.println("读取悲剧了....");
  } finally {
   in = null;
   dos = null;
   baos = null;
  }
  return strReturn;
 }
}

 

 

=====================================华丽的分割线=========================================

package com.RayiDream;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class GetData extends MIDlet {

 public GetData() {

 }

 protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
 }

 protected void pauseApp() {
 }

 protected void startApp() throws MIDletStateChangeException {
  Display.getDisplay(this).setCurrent(new DrawData());
 }
}

 

 

运行结果:

图片

 

               图片     图片

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值