简单的Java Web服务器

 1 import java.io.FileInputStream;
 2 import java.io.OutputStream;
 3 import java.net.ServerSocket;
 4 import java.net.Socket;
 5 
 6 public class Server {
 7 
 8     /**
 9      * @param args
10      */
11     public static void main(String[] args) throws Exception{
12         // TODO Auto-generated method stub
13         ServerSocket server = new ServerSocket(9999);
14         Socket sock = server.accept();
15         FileInputStream in = new FileInputStream("c:\\a\\1.html");
16         OutputStream out = sock.getOutputStream();
17         int len = 0;
18         byte buffer[] = new byte[1024];
19         while((len = in.read(buffer)) > 0){
20             out.write(buffer, 0, len);
21         }
22         in.close();
23         out.close();
24         sock.close();
25         server.close();
26     }
27 
28 }

 

posted @ 2014-05-29 17:59  logx  阅读(217)  评论(0编辑  收藏  举报