int len = request.getContentLength();  
byte buffer[] = new byte[len];  

解决方案 »

  1.   

    request.getContentLength()获取到的值为-1,文件确实是传上来的了,因为我测试用// FileOutputStream fos = new FileOutputStream("F://123.jpg");
    // int len = 0;
    // byte[] bytes = new byte[1024];
    // while((len = in.read(bytes))!=-1){
    // fos.write(bytes, 0, len);
    // fos.flush();
    // }
    // fos.close();确实是把文件写下来了,但因为需求需要写到一个字节数组中,现在写不进去
      

  2.   

    request.getContentLength()获取到的值为-1,文件确实是传上来的了,因为我测试用// FileOutputStream fos = new FileOutputStream("F://123.jpg");
    // int len = 0;
    // byte[] bytes = new byte[1024];
    // while((len = in.read(bytes))!=-1){
    // fos.write(bytes, 0, len);
    // fos.flush();
    // }
    // fos.close();确实是把文件写下来了,但因为需求需要写到一个字节数组中,现在写不进去你不是上传吗?
    表单的enctype="multipart/form-data" 是否设置了?
    是post请求吧?
    如果是get请求length是-1
      

  3.   

    request.getContentLength()获取到的值为-1,文件确实是传上来的了,因为我测试用// FileOutputStream fos = new FileOutputStream("F://123.jpg");
    // int len = 0;
    // byte[] bytes = new byte[1024];
    // while((len = in.read(bytes))!=-1){
    // fos.write(bytes, 0, len);
    // fos.flush();
    // }
    // fos.close();确实是把文件写下来了,但因为需求需要写到一个字节数组中,现在写不进去你不是上传吗?
    表单的enctype="multipart/form-data" 是否设置了?
    是post请求吧?
    如果是get请求length是-1
    android客户端传上来的,等下跟他们确认下,刚用了个笨方法File file = new File("F:\\abc.jpg");


    FileOutputStream fos = new FileOutputStream(file);
    int len = 0;
    byte[] bytes = new byte[1024];
    while((len = in.read(bytes))!=-1){
    fos.write(bytes, 0, len);
    fos.flush();
    }
    fos.close();
    System.out.println(file.length());
    in = new FileInputStream(file);
    byte[] temp = new byte[(int) file.length()];
    in.read(temp);先写入一个临时文件,在获取文件的大小,然后就成功了。
      

  4.   

    request.getContentLength()获取到的值为-1,文件确实是传上来的了,因为我测试用// FileOutputStream fos = new FileOutputStream("F://123.jpg");
    // int len = 0;
    // byte[] bytes = new byte[1024];
    // while((len = in.read(bytes))!=-1){
    // fos.write(bytes, 0, len);
    // fos.flush();
    // }
    // fos.close();确实是把文件写下来了,但因为需求需要写到一个字节数组中,现在写不进去你不是上传吗?
    表单的enctype="multipart/form-data" 是否设置了?
    是post请求吧?
    如果是get请求length是-1
    请问下如果是get方式提交的话,有没有其他办法获取到上传上来的文件的大小的