本帖最后由 戴乾刚 于 2013-3-28 14:23 编辑
为什么用while循环时,下面代码输出“注册成功”的那条语句执行不到、(浏览器访问)- import java.net.*;
- import java.io.*;
- class RegServer
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(1010);
- Socket s = ss.accept();
- InputStream in = s.getInputStream();
- OutputStream out = s.getOutputStream();
- PrintWriter pw = new PrintWriter(out,true);
- byte[] buf = new byte[1024];
- int len;
- /*while((len=in.read(buf))!=-1) //为什么用while语句,“注册成功那条语句发送不到浏览器”
- {
- System.out.print(new String(buf,0,len));
- }*/
- len = in.read(buf);
- System.out.println(new String(buf,0,len));
- pw.print("<font size=5 color=red>注册成功</font>");
- ss.close();
- pw.close();
- }
- }
复制代码 |