int 是4个字节,我想先读头一个int行吗?程序如下: int bytes_read; byte[] byteArray = new byte[4]; in = new DataInputStream(socket.getInputStream()); if ( (bytes_read = in.read(byteArray)) != -1) 怎么好像没读进来呢?
为什么没有错误提示呢?编译没问题。 byte[] byteArray = new byte[4]; int bytes_read; try{ Socket socket = new Socket("192.168.3.59",7001); System.out.println(socket); DataInputStream in = null; in = new DataInputStream(socket.getInputStream()); if(in == null){ System.out.println("in is null"); } else{ System.out.println("in is not null"); } if ( (bytes_read = in.read(byteArray)) != -1) { } }catch(Exception wrong1){ System.out.println(wrong1); } 为什么运行到bytes_read = in.read(byteArray)) 就死了呢?什么原因呢?
static put(String name, char val) ,两个方法
ObjectInputStream.GetField类有static get(String name,int val)
static get(String name ,char val)两个方法用这两个方法看看吧我没试过
……
int bytes_read;
byte[] byteArray = new byte[4];
in = new DataInputStream(socket.getInputStream());
if ( (bytes_read = in.read(byteArray)) != -1) 怎么好像没读进来呢?
byte[] byteArray = new byte[4];
int bytes_read;
try{
Socket socket = new Socket("192.168.3.59",7001);
System.out.println(socket);
DataInputStream in = null;
in = new DataInputStream(socket.getInputStream());
if(in == null){
System.out.println("in is null");
}
else{
System.out.println("in is not null");
}
if ( (bytes_read = in.read(byteArray)) != -1) {
}
}catch(Exception wrong1){
System.out.println(wrong1);
}
为什么运行到bytes_read = in.read(byteArray)) 就死了呢?什么原因呢?