Detailed Java method to send a file to the server _java

Source: Internet
Author: User
Tags readline

This article for you to share the Java to the server to send the file method for your reference, the specific content as follows

* * Send a file to the server, mainly IO stream. 
* * Import java.io.*; 
Import java.net.*; Class Send2 {public static void main (string[] args) throws Exception {socket s = new Socket ("192.168.33.1", 1 0005)//Establish service BufferedReader BUFR = new BufferedReader (New FileReader ("Io.java"))//Read Io.java file PrintWriter pw = 
    New PrintWriter (S.getoutputstream (), true);//Read to the Write service-side String line = null; 
    while (line = Bufr.readline ())!=null) {pw.println (line); 
    //Pw.println ("over");//Mark End position S.shutdownoutput (); BufferedReader Bufin = new BufferedReader (New InputStreamReader (S.getinputstream ());//Read server-side returned data String str = Bufin. 
    ReadLine (); 
    System.out.println (str); 
    Bufr.close (); 
  S.close (); } class Rece2 {public static void main (string[] args) throws Exception {ServerSocket ss = new Serversock ET (10005);//Establish service Socket s = ss.accept ();//Receive data BufferedReader Bufin = new BufferedReader (new InputStreamReader (s . getInputStream ())//Read received data printwriter out = new PrintWriter (New FileWriter ("Io2.txt"), true);//write to IO.TXT text String = null; 
      while (line = Bufin.readline ())!= null)//read one row to write a row {//if ("Over", Equals (line))//break; 
    Out.println (line); 
    } printwriter pw = new PrintWriter (S.getoutputstream (), true); Pw.println ("Upload success!") 
    "); 
    Out.close (); 
    Ss.close (); 
  S.close (); 
 } 
}

Results:

The above is the whole content, I hope to give you a reference, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.