当前位置: 技术问答>java相关
我在写一个socket类的时候遇到一个问题,帮忙看看!!
来源: 互联网 发布时间:2015-11-11
本文导语: "UDPGet.java": Warning #: 368 : constructor String(byte[], int, int, int) in class java.lang.String has been deprecated at line 45, column 24 源程序段为: byte[] buffer=new buffer[1024]; DatagramPacket packet=new DatagramPacket(buffer,buffer.length); Data...
"UDPGet.java": Warning #: 368 : constructor String(byte[], int, int, int) in class java.lang.String has been deprecated at line 45, column 24
源程序段为:
byte[] buffer=new buffer[1024];
DatagramPacket packet=new DatagramPacket(buffer,buffer.length);
DatagramSocket socket=new DatagramSocket(2222);
while (true) {
socket.receive(packet);
String s=new String(buffer,0,0,packet.getLength());
textArea.append(s+"n");
packet=new DatagramPacket(buffer,buffer.length);
}
源程序段为:
byte[] buffer=new buffer[1024];
DatagramPacket packet=new DatagramPacket(buffer,buffer.length);
DatagramSocket socket=new DatagramSocket(2222);
while (true) {
socket.receive(packet);
String s=new String(buffer,0,0,packet.getLength());
textArea.append(s+"n");
packet=new DatagramPacket(buffer,buffer.length);
}
|
String s=new String(buffer,0,0,packet.getLength());有问题,新的JDK版本不建议使用这种构造String的方法。
|
下面这行是否有问题????
byte[] buffer=new buffer[1024];
应该为
byte[] buffer=new byte[1024];
byte[] buffer=new buffer[1024];
应该为
byte[] buffer=new byte[1024];
|
同意楼上