- //上传图片多客户端上传
- 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();
- }
- }
复制代码
这代码怎么角标越界了呢 |
|