标题: daima [打印本页] 作者: heqinghui 时间: 2019-10-10 13:26 标题: daima public class Dati4Server { public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(8888);
Socket s = ss.accept();
InputStream is = s.getInputStream();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("F:\\IdeaProjects\\DayDayUP\\copy.jpg")); byte[] bys = new byte[1024]; int len; while ((len = is.read(bys)) != -1) {
bos.write(bys, 0, len);
bos.flush();
}
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
bw.write("上传成功!");
bw.newLine();
bw.flush();
bw.close();
is.close();
ss.close();
}
}public class Dati4Client { public static void main(String[] args) throws IOException {
Socket s = new Socket("127.0.0.1",8888);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\tupian.jpg"));
OutputStream os = s.getOutputStream(); byte[] bys = new byte[1024]; int len; while ((len=bis.read(bys))!=-1){
os.write(bys,0,len);
}
s.shutdownOutput();