m0_37844930
小小cheng婿员
2017-06-30 08:50

java IO在写入文件的时候到了8192字节以后就报异常

50
  • java
  • 异常

HttpClient httpclient = new HttpClient();

    File file = new File("D:\\cirros-0.3.4-x86_64-disk.img");//一个本地20多M的假镜像
    PutMethod put = new PutMethod("");//我使用httpclient3.1传输文件
    BufferedOutputStream bos = null;
    BufferedInputStream bis = null;
    //下面是将文件写入http的(OutputStream) put.getRequestEntity()中
    bos = new BufferedOutputStream((OutputStream) put.getRequestEntity());
    try {
        bis = new BufferedInputStream(new FileInputStream(file));
        byte[] buff = new byte[1024];
        int i;
        while ((i = bis.read(buff)) >= 0) {//这里前8次写入都没问题,到了第九次就会报异常了  异常是空指针,什么鬼呢?新手勿喷各位大神
            bos.write(buff, 0, i);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答