<分区>
Possible Duplicate:
Is it possible to read from a Java InputStream with a timeout?
我注意到当我尝试阅读更多信息然后发送到我的服务器时,网络浏览器会卡住。我看到我的套接字卡住了,因为网络浏览器返回的信息少于它试图读取的信息。有没有办法在 Currtly 上设置超时?我正在使用输入流
public String ReadLine()
{
String out;
out="";
// read in one line
try{
request = new StringBuffer(1000);
boolean f=true;
while(true)
{
int c=in.read();
if (c=='\r')
{
// next should be a \n
// Program freezed hear
c=in.read();
if (f==true)
return "";
break;
}
f=false;
out=out+(char)c;
request.append((char)c);
} // end while
} catch(IOException ec)
{
System.out.println(ec.getMessage());
}
System.out.println(request);
return out;
}