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.