日期:2014-05-20  浏览次数:20711 次

求助一个关于asp服务器端,J2ME客户端的问题!很急!望大虾解答!
原因是这样的,我现在用j2me去抓取asp一个网址的内容!用输入流中的read()方法去读取的数据,结果,在诺基亚手机中汉字显示正常,但到了moto手机中就显示乱码了!我问了一个搞过j2me的朋友,他告诉我用readUTF()方法去读取输入流就不存在这些问题了,可是一用这方法就报错,后来知道,在服务器端要有与之对应的writeUTF()的方法,可是我不知道asp到底有没有类似于writeUTF()的方法,如果没有,我该怎么处理j2me客户端产生的这个乱码问题!望高手解答!在线等!

------解决方案--------------------
两种方法解决:
1.两端都使用单纯的read()和write()方法,只要双方指定一个统一的编码格式就可以了;

2.在asp服务器模拟一个writeUTF()方法的数据格式,最近几天问这个的人比较多,我刚查过API,writeUTF()的格式如下
First, two bytes are written to the output stream as if by the writeShort method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the UTF-8 encoding for the character.
你照这个格式自己实现一个writeUTF()方法即可
------解决方案--------------------
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
dataOutputStream.writeUTF(流数据);


或者是input !!

------解决方案--------------------
asp控制输出流自己转换,不过有时候也带来方便!