package Day12;
import java.io.*;
import java.net.Socket;
public class KeTang04 {
public static void main(String[] args) throws IOException {
Socket at =new Socket("192.168.19.92",10000);
OutputStream ous = at.getOutputStream();
// byte [] by ="123".getBytes();
// ous.write(by);
// BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new FileReader("F:\\day11天练习.docx"));
BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(at.getOutputStream()));
String line;
while ((line=br.readLine())!=null){
bw.write(line);
bw.newLine();
bw.flush();
}
at.shutdownOutput();
// InputStream is = at.getInputStream();
// byte [] bys =new byte[1024];
// int data = is.read(bys);
// String s = new String(bys, 0, data);
// System.out.println(s);
BufferedReader brr = new BufferedReader(new InputStreamReader(at.getInputStream()));
System.out.println(brr.readLine());;
at.close();
}
}
package Day12;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class KeTang05 {
public static void main(String[] args) throws IOException {
ServerSocket ss =new ServerSocket(10000);
Socket s = ss.accept();
// InputStream is = s.getInputStream();
// byte [] by =new byte[1024];
// int len = is.read(by);
// System.out.println(new String(by,0,len));
// OutputStream ous = s.getOutputStream();
// ous.write("收到".getBytes());
BufferedReader br =new BufferedReader( new InputStreamReader(s.getInputStream()));
BufferedWriter bw =new BufferedWriter(new FileWriter("ServerTread\\s.txt"));
String line;
while ((line =br.readLine())!=null){
bw.write(line);
bw.newLine();
bw.flush();
}
BufferedWriter bww=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
bww.write("接收成功!");
bww.newLine();
bww.flush();
ss.close();
bw.close();
}
}
|
|