为什么我用getinputStream接收过来的数据都带个口???

liujava8 2006-03-21 01:25:15
InputStream is=socket.getInputStream();
byte barr[]=new byte[1024];

// while(true)
// {
int kk=is.read(barr,0,1024);
if(kk==-1)
{
chatServer.SetRecText("Read Error"); }
else if(kk==0)
{
chatServer.SetRecText("Read Nothing");
}
else
{
line=new String(barr,0,kk,"utf-8");
chatServer.SetRecText("Read:" + line);
}

如上。如果接收过来的是abc。那么就会在后面加上个口成了abc口。为什么呀?
换把编码换成gb2312的也这样。
...全文
117 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
软若石 2006-03-24
  • 打赏
  • 举报
回复
尚观
piaopiao11 2006-03-21
  • 打赏
  • 举报
回复
试试 line=line.trim();
liujava8 2006-03-21
  • 打赏
  • 举报
回复
line=new String(barr,0,kk,"iso8859-1");
line=new String(line.getBytes("gb2312"),"iso8859-1");
chatServer.SetRecText("Read:" + line);

改成这样了还不行。接收的数据是Flash发过来的。Flash发数据好像在每一句后面都加上了个\0。
fangshao 2006-03-21
  • 打赏
  • 举报
回复
可能是编码问题

package lib;
import java.io.*;

public class CodeChange

{
public static String DustTOChin(String dust) throws IOException

{
String chin="";
chin=new String(dust.getBytes("iso8859-1"),"gb2312");
return chin;
}

public static String ChinToDust (String chin) throws IOException

{
String dust="";
dust=new String(chin.getBytes("gb2312"),"iso8859-1");
return dust;
}
}

转哈子试试看
剑事 2006-03-21
  • 打赏
  • 举报
回复
BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
in.close();

用这个呢
cleansunshing 2006-03-21
  • 打赏
  • 举报
回复
mark

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧