- import java.io.*;
 
 - import java.net.*;
 
 - class  PicClient{
 
 -         public static void main(String[] args) throws Exception{
 
 -                 Socket s=new Socket("127.0.0.1",10002);
 
 -                 FileInputStream fis=new FileInputStream("xiaomao.jpg");
 
 -                 OutputStream out=s.getOutputStream();
 
 -                 byte[] buf=new byte[1024];
 
 -                 int len=0;
 
 -                 while((len=fis.read(buf))!=-1){
 
 -                         out.write(buf,0,len);
 
 -                 }
 
 -                 s.shutdownOutput();
 
 -                 InputStream in=s.getInputStream();
 
 -                 byte[] by=new byte[1024];
 
 -                 int num=in.read(by);
 
 -                 System.out.println(new String(by,0,num));
 
 -                 fis.close();
 
 -                 s.close();
 
 -         }
 
 - }
 
 - class PicServer {
 
 -         public static void main(String[] args)throws Exception{
 
 -                 ServerSocket ss=new ServerSocket(10002);
 
 -                 Socket s=ss.accept();
 
 -                 System.out.println(s.getInetAddress().getHostAddress()+"....connected");
 
 -                 FileOutputStream fos=new FileOutputStream("taoqi.bmp");
 
 -                 InputStream in=s.getInputStream();
 
 -                 byte[] buf=new byte[1024];
 
 -                 int len=0;
 
 -                 while((len=in.read(buf))!=-1){
 
 -                         fos.write(buf,0,len);
 
 -                 }
 
 -                 OutputStream out=s.getOutputStream();
 
 -                 out.write("上传成功".getBytes());
 
 -                 fos.close();
 
 -                 s.close();
 
 -         }
 
 - }
 
 
  复制代码 
这个程序自己可以写出来,但总觉得缺少点什么,不知道哪里理解的不到位,或者还是根本就理解的不到位,还是直接理解成  文件读取流关联文件,将文件写入输出流,然后就接受服务器发送过来的输出流,服务器用文件输出流写入文件,发送提示,这种模式,是不是欠缺什么 |