Java NIO??IO???????
???????????? ???????[ 2014/10/21 10:39:02 ] ????????Java ???????
????????
????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();
????????????д???????????????????????д?????????????Ч????£??????????????????????????????壬???????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11