用socket来读取某一网页的内容,获得输入流,在循环用readLine()读流内容时,结束不掉,
不知什么原因................
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream());for (; ;)
{
     String content = br.readLine();
     if(content==null) break;
}
System.out.println("读取结束");

解决方案 »

  1.   

    public void socketIncept()
        {
            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();
        }
      

  2.   

    while ((str = in.readLine()) != null)用这个来判断!
      

  3.   

    还有用while ((str = in.readLine()) != null)这个也不行   流读取还是不能结束!!郁闷死了!!!   有谁遇到类似的问题?????
      

  4.   

    当然用while ((str = in.readLine()) != null)
      

  5.   

    不要用readline()来读取socket流中的数据,因为如果socket流的数据没有换行符的话,这句话是不会返回的...
    应该这样:
    InputStream in = sk.getInputStream();
    byte[] buf = new byte[1024];
    in.read(buf);
    String msg = new String(buf, "gb2312");