Reading UTF8 strings from a server through http using MIDP

◇◆丶佛笑我妖孽 提交于 2019-12-05 10:29:33
lavinio

Instead of reading bytes, read characters. Use an InputStreamReader API to convert bytes to characters and run through the UTF-8 encoder. It should be supported as part of the JavaME CLDC (JSR 30) profile; that's where the link points.

Try something like this:

c = (StreamConnection) Connector.open(
         myServer, Connector.READ_WRITE);
Reader r = new InputStreamReader(c.openInputStream(), "UTF-8");
StringBuffer sb = new StringBuffer();
int ch;
while((ch = r.read()) != -1)
    sb.append((char)ch + "->" + ch + "\n");
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!