客户端键盘录入,服务器输出文本文件
服务器端
package net_study_08;import java.io.*;import java.net.ServerSocket;import java.net.Socket;public class ServerDemo {public static void main(String[] args) throws IOException {ServerSocket ss =new ServerSocket(9999);Socket s=ss.accept();BufferedReader br =new BufferedReader(new InputStreamReader(s.getInputStream()));BufferedWriter bw =new BufferedWriter(new FileWriter(\"IO.txt\"));String line =null;while((line=br.readLine())!=null){bw.write(line);bw.newLine();bw.flush();}}}
客户端
package net_study_08;import java.io.*;import java.net.Socket;public class ClientDemo {public static void main(String[] args) throws IOException {Socket s =new Socket(\"192.168.10.103\",9999);BufferedReader br =new BufferedReader(new InputStreamReader(System.in));BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));String line =null;while((line=br.readLine())!=null){if (line.equals(\"886\")){break;}bw.write(line);bw.newLine();bw.flush();}s.close(); }}