package cn.idcast10;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.net.Socket;/* * 客户端读取文本文件,服务器端输出到控制台 */public class ClientDemo { public static void main(String[] args) throws IOException { Socket s = new Socket("192.168.1.115", 11111); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( s.getOutputStream())); BufferedReader br = new BufferedReader(new FileReader("ip.java")); String line = null; while ((line = br.readLine()) != null) { bw.write(line); bw.newLine(); bw.flush(); } br.close(); s.close(); }}
package cn.idcast10;import java.io.BufferedReader;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(11111); Socket s = ss.accept(); BufferedReader br = new BufferedReader(new InputStreamReader( s.getInputStream())); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } }}