byte[] bytes = new byte[64];
//读取输入流数据
int readLen = 0;
while((readLen = input.read())>0){
System.out.println(readLen);
}
今天在练习soket编程的时候遇到这么个问题,每次程序运行到上面代码第5行时就会挂起。
后来把代码改成这样
byte[] bytes = new byte[64];
//读取输入流数据
int readLen = 0;
while((readLen = input.available())>0){
System.out.println(readLen);
input.read(bytes,0,5);
}
程序就可以正常运行了,我想是当我们试图去读取一个为空的输入流时,程序会自动等待,直到客户端再次有数据写入。这应该是SoketInputStream独有的特性。