/** Client 1, service Endpoint 2, read the client's existing file data 3, through the socket output stream to the server 4, read the service side Feedback 5, close **/import java.io.*;import java.net.*;class uploadclient{public static void Main (string[] args) throws Exception{Socket s = new socket ("127.0.0.1", 4434);FileInputStream fis = new FileInputStream ("D://2.png");OutputStream out = S.getoutputstream ();byte[] buf = new byte[1024];int len = 0;while (len = Fis.read (buf))!=-1){Out.write (Buf,0,len);}Execution of Shutdownoutput when data is completeS.shutdownoutput ();InputStream is = S.getinputstream ();byte[] Bufin = new byte[1024];int lenin = Is.read (Bufin);System.out.println (New String (Bufin,0,lenin));Fis.close ();S.close ();}}/** server-side */class uploadserver{public static void Main (string[] args) throws Exception{ServerSocket ss = new ServerSocket (4434);Socket s = ss.accept ();InputStream is = S.getinputstream ();FileOutputStream fos = new FileOutputStream ("c://test.jpg");byte[] buf = new byte[1024];int len = 0;while (len = Is.read (buf))!=-1){Fos.write (buf,0,buf.length);}OutputStream out = S.getoutputstream ();Out.write ("Upload succeeded". GetBytes ());Fos.close ();S.close ();Ss.close ();}}
---Reprint of TCP file transfer