java io 和 nio socket

ServerSocket 是服务器端的socket服务器

ServerSocket serverSocket = new ServerSocket(9000);
通过 socket = serverSocket.accept();   获得一个socket链接

InputStream 输入流

通过 inputStream inputStream = socket.getInputStream(); 获得一个输入流, 
可以直接
int data = inputStream.read();
while (data != -1){
    Character character = (char)data;
    System.out.print(character);
    data = inputStream.read();
}

读出数据
或者放入缓存后再读出数据
Reader  reader = new BufferedReader(new     InputStreamReader(socket.getInputStream()));

3.outputStream 输出流

OutputStream outputStream =  socket.getOutputStream();
Writer out = new BufferedWriter(new                    OutputStreamWriter(outputStream));
out.write("success");
out.flush();

代码是通过缓存后输出,或者也可以直接输出