????????
????J2SE1.4????汾???й???????μ?I/O??????????????Щ????????NIO???????Щ????????????I/O??????????????????????
?????. ????NIO
????NIO????java.nio.*??????????????????????????????????????????I/O???е??Щ????
????1?? Buffer????????????????????д?????α???????л?????????????????????????????I/O??????
????2?? Charset??????Unicode?????????????????????????????
????3?? Channels??????socket??file??pipe?????????????????????????????
????4?? Selector???????????I/O???????е????????????У??????????????Unix??select??????????Win32??WaitForSingleEvent?????????????????汾?????
??????. ?????
?????????NIO?????б????????I/O????????????????????????????????????????ServerSocket?????????????????????????????????????????????????????????server????????????????б??д??????????????????I/O??????


????
??

???????????????server????????????衣???????ServerSocket
????ServerSocket server=new ServerSocket??10000????
???????????μ?????????
????Socket newConnection=server.accept??????
????????accept????????y????????????ServerSocket????????????????????????????????????server????????socket?е?????
????InputStream in = newConnection.getInputStream();
????InputStreamReader reader = new InputStreamReader(in);
????BufferedReader buffer = new BufferedReader(reader);
????Request request = new Request();
????while(!request.isComplete()) {
????String line = buffer.readLine();
????request.addLine(line);
????}
?????????????????????????BufferedReader???readLine???????????仺????δ?????????????????????????????????????????????????????????????????????Σ????????????????????BufferedReader????????????????????????????????????????????Щ??????洢??Щ?????????BufferedReader???????StringBuffer????????????????????String?????????????????????
????????????????????????????????
????Response response = request.generateResponse();
????OutputStream out = newConnection.getOutputStream();
????InputStream in = response.getInputStream()??
????int ch??
????while(-1 != (ch = in.read())) {
????out.write(ch);
????}
????newConnection.close();
????????????д???????????????????????д?????????????Ч????£??????????????????????????????壬???????????????????????