黑马程序员技术交流社区
标题:
java.lang.ArrayIndexOutOfBoundsException
[打印本页]
作者:
chenyannna
时间:
2015-9-21 16:45
标题:
java.lang.ArrayIndexOutOfBoundsException
//上传图片多客户端上传
public class TcpClient5 {
public static void main(String[] args) throws Exception {
//限制上传的东西。要在客户端上传
File file = new File(args[0]);
if(!(file.getName().endsWith(".jpg"))){
System.out.println("传输文件格式错误");
return;
}
// 添加自己的ip地址
Socket s = new Socket("192.168.0.4", 8765);
FileInputStream fis = new FileInputStream(file);
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[] bufIn = new byte[1024];
int num = in.read(bufIn);
System.out.println(new String(bufIn, 0, num));
fis.close();
s.close();
}
}
复制代码
这代码怎么角标越界了呢
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2