AI智能
改变未来

学习博客:TCP客户端文本文件,服务器输出到控制台


TCP客户端文本文件,服务器输出到控制台

客户端

package net_study_09;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\",7777);BufferedReader br =new BufferedReader(new FileReader(\"IO.txt\"));BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));String  line =null;while((line=br.readLine())!=null){bw.write(line);bw.newLine();bw.flush();}s.close();}}

服务器端:

package net_study_09;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStreamReader;import java.net.ServerSocket;import java.net.Socket;public class ServerDemo {public static void main(String[] args) throws IOException {ServerSocket ss= new ServerSocket(7777);Socket s =ss.accept();BufferedReader  bw =new BufferedReader(new InputStreamReader(s.getInputStream()));String line =null;while((line=bw.readLine())!=null){System.out.println(line);}s.close();}}
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 学习博客:TCP客户端文本文件,服务器输出到控制台