1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public class FileUploadClient { public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("G:\\test\\demo\\test\\text\\tt\\新建文件夹\\timg.jpg");
Socket socket = new Socket("127.0.0.1",8888); OutputStream os = socket.getOutputStream(); int len = 0; byte[] bytes = new byte[1024]; while((len = fis.read(bytes))!=-1){ os.write(bytes,0,len); } socket.shutdownOutput();
InputStream is = socket.getInputStream(); while((len = is.read(bytes))!=-1){ System.out.println(new String(bytes,0,len)); }
fis.close(); socket.close(); } }
|