• tcp上传学习二--文本文件上传


            //暮雪超霸、加油!!!
    package
    tcp文本上传; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; public class UploadClient { public static void main(String[] args) throws UnknownHostException, IOException { Socket s=new Socket("127.0.0.1", 10008); BufferedReader bufIn=new BufferedReader(new FileReader("chaoba.txt")); PrintWriter pw=new PrintWriter(s.getOutputStream(),true); String line=null; while((line=bufIn.readLine())!=null){ pw.println(line); } s.shutdownOutput(); BufferedReader buf=new BufferedReader(new InputStreamReader(s.getInputStream())); String readLine = buf.readLine(); System.out.println(readLine); bufIn.close(); s.close(); } }
    package tcp文本上传;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    public class UploadServer {
    public static void main(String[] args) throws IOException {
        ServerSocket ss=new ServerSocket(10008);
        Socket accept = ss.accept();
        BufferedReader bufIn =new BufferedReader(new InputStreamReader(accept.getInputStream()));
        String line=null;
        BufferedWriter bufw=new BufferedWriter(new FileWriter("server.txt"));
        while((line=bufIn.readLine())!=null){
            bufw.write(line);
            bufw.newLine();
            bufw.flush();
        }
        
        PrintWriter  pw=new PrintWriter(accept.getOutputStream(),true);
        pw.println("上传成功");
        bufw.close();
        accept.close();
        ss.close();
        
        
    }
    }
    一万年太久,只争朝夕!
  • 相关阅读:
    如何在winform的numericUpDown中显示小数点
    Jquery attr 和removeAttr 的简单使用
    Linux下的多进程编程初步(转载)
    扩展GCD和线性模方程组
    05、Flutter常用组件
    12、Flutter组件装饰
    10、Flutter资源和图片
    09、Flutter手势控制
    04、FlutterDart语法
    07、FluterCupertino
  • 原文地址:https://www.cnblogs.com/chaoba/p/6956867.html
Copyright © 2020-2023  润新知