A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

  1. //上传图片多客户端上传
  2. public class TcpClient5 {
  3.         public static void main(String[] args) throws Exception {
  4. //限制上传的东西。要在客户端上传                                       
  5.                 File file = new File(args[0]);
  6.                 if(!(file.getName().endsWith(".jpg"))){
  7.                         System.out.println("传输文件格式错误");
  8.                         return;
  9.                         }               
  10.                 // 添加自己的ip地址
  11.                 Socket s = new Socket("192.168.0.4", 8765);
  12.                 FileInputStream fis = new FileInputStream(file);
  13.                 OutputStream out = s.getOutputStream();
  14.                 byte[] buf = new byte[1024];
  15.                 int len = 0;
  16.                 while ((len = fis.read(buf)) != -1) {
  17.                         out.write(buf, 0, len);
  18.                 }
  19.                 s.shutdownOutput();
  20.                 InputStream in = s.getInputStream();
  21.                 byte[] bufIn = new byte[1024];
  22.                 int num = in.read(bufIn);
  23.                 System.out.println(new String(bufIn, 0, num));
  24.                 fis.close();
  25.                 s.close();
  26.         }
  27. }
复制代码





这代码怎么角标越界了呢

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马