java中接收不到汉字最后一个字符以后的字符,
我用java写的一个udp程序,为什么接收不到输入的汉字最后一个字符以后的字符,比如输入"你好aaaa"接收到的只有"你 "后面的没了 什么问题,知道的说下!public class Chat extends Frame
{
List lst = new List(6);
TextField tfIP = new TextField(15);
TextField tfInfo = new TextField(20);
DatagramSocket ds = null;
public Chat()
{
try
{
ds = new DatagramSocket(3000);
}
catch (Exception e)
{
e.printStackTrace();
}
this.add(lst,"Center");
Panel p = new Panel();
this.add(p,"South");
p.setLayout(new BorderLayout());
p.add(tfIP,"West");
p.add(tfInfo,"East");
new Thread (new Runnable()
{
public void run()
{
byte [] buff = new byte[2048];
DatagramPacket dp = new DatagramPacket(buff,2048);
while(true)
{
try
{
ds.receive(dp);
//System.out.println(dp.getData());
String str = new String(dp.getData(),0,dp.getLength()) +"length="+dp.getLength()
+" from "+dp.getAddress().getHostAddress() +":"+dp.getPort();
//String str = new String (info.getBytes("iso-8859-1"),"GB2312");
lst.add(str,0);
}
catch (Exception e)
{
if(!ds.isClosed())
{
e.printStackTrace();
}
}
}
}
}).start();
tfInfo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
byte [] buff = tfInfo.getText().getBytes();
try
{
DatagramPacket dp = new DatagramPacket(buff,tfInfo.getText().length(),InetAddress.getByName(tfIP.getText()),3000);
System.out.println(tfInfo.getText());
ds.send(dp);
}
catch (Exception ex)
{
ex.printStackTrace();
}
tfInfo.setText("");
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
ds.close();
dispose();
System.exit(0);
}
});
}
----------------解决方案--------------------------------------------------------
这个不会!
----------------解决方案--------------------------------------------------------