//客户端public class ClientDemo02 {
public static void main(String[] args) throws IOException {
Socket s = new Socket("127.0.0.1",12345);
BufferedReader br = new BufferedReader(new FileReader("javaplus\\b.txt"));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
String line;
while ((line = br.readLine()) != null){
bw.write(line);
bw.newLine();
bw.flush();
}
br.close();
s.close();
}//服务器public class ServerTcpDemo02 {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(12345);
Socket sa = ss.accept();
BufferedReader br = new BufferedReader(new InputStreamReader(sa.getInputStream()));
BufferedWriter bw = new BufferedWriter(new FileWriter("javaplus\\c.txt"));
String line;
while ((line = br.readLine()) != null){
bw.write(line);
bw.newLine();
bw.flush();
}
bw.close();
ss.close();
}
}
|
|