Client

来源:互联网 发布:qq牧场羽鹤升级数据 编辑:程序博客网 时间:2024/06/10 15:07
 

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class Client {
 public static void main(String[] args) {
  BufferedWriter bw = null;
  Socket s = null;
  InputStream is = null;
  byte[] buf = new byte[100];
  int len = 0;
  try {
   s = new Socket("127.0.0.1", 5555);
   ;
   bw = new BufferedWriter(new FileWriter("E:\\test2.txt"));
   is = s.getInputStream();
   len = is.read(buf);
   bw.write(new String(buf, 0, len));
   System.out.println(new String(buf, 0, len));
   bw.flush();
  } catch (Exception ex) {
   ex.printStackTrace();
  } finally {
   try {
    is.close();
    s.close();
    bw.close();
   } catch (IOException e) {
    System.out.println(e.getMessage());
   }
  }
 }
}

原创粉丝点击