A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 江山美人 初级黑马   /  2019-4-11 14:00  /  703 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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();
    }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马