本帖最后由 黑马晓志 于 2014-4-26 12:59 编辑
自己写的服务器代码,为什么浏览器访问不到页面
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.OutputStreamWriter;
- import java.net.ServerSocket;
- import java.net.Socket;
- public class MyServer
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket server=new ServerSocket(9999);
- Socket socket=server.accept();
-
- BufferedReader bufferedReader=new BufferedReader(new FileReader("c:\\jingtian.html"));
- BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
-
- String line=null;
- while((line=bufferedReader.readLine())!=null){
- bufferedWriter.write(line);
- System.out.println(line);
- bufferedWriter.newLine();
- bufferedWriter.flush();
- }
-
- bufferedReader.close();
- bufferedWriter.close();
- socket.close();
- server.close();
- }
- }
复制代码
|
|