用socket来读取某一网页的内容,获得输入流,在循环用readLine()读流内容时,结束不掉,
不知什么原因................
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream());for (; ;)
{
String content = br.readLine();
if(content==null) break;
}
System.out.println("读取结束");
{
try
{
String str = new String();
message = "";
in = new BufferedReader(
new InputStreamReader(socketClient.getInputStream()));
while ((str = in.readLine()) != null)
{
message = message + str + "\n";
str = str.trim();
if (str.endsWith(con_sendMessageTail2))
{
break;
}
}
log("Accept message is : " + message , 3);
}
catch (IOException e)
{
log(con_timeOutError , 1);
JOptionPane.showMessageDialog(this , con_timeOutError ,
con_errorDialogTitle , JOptionPane.ERROR_MESSAGE);
socketClose();
return;
}
inFile();
}
应该这样:
InputStream in = sk.getInputStream();
byte[] buf = new byte[1024];
in.read(buf);
String msg = new String(buf, "gb2312");