我需要用 request.getInputStream(); 获取用户发过来的信息然后要放入NIO里去请问怎么把request.getInputStream(); 获得的数据流 转换成NIO可以识别的数据?要具体代码!

解决方案 »

  1.   

    Java NIO非堵塞技术
    没用过呢,
    这么冷清
    帮兄弟顶一下!
      

  2.   

    public void testNio() throws Exception { 
    ByteArrayInputStream bis = new ByteArrayInputStream("This is the buffer".getBytes());

    File f = File.createTempFile("nio", ".tmp");
    System.out.println("testNio(): " + f.getAbsolutePath());
    FileOutputStream fos = new FileOutputStream(f); // replace with InputStream inputstream = request.getInputStream();
    FileChannel fc = fos.getChannel();
    byte[] bytes = new byte[4];

    while (true) {
    int readCount = bis.read(bytes); // read bytes
    if (readCount == -1) break;
    fc.write(ByteBuffer.wrap(bytes, 0, readCount)); // use ByteBuffer.wrap to wrap byte[] for NIO
    }
    }
      

  3.   

    我要的不是文件流
    我要的是从request对象里面获得的数据流
      

  4.   

     FileOutputStream fos = new FileOutputStream(f); // replace with InputStream inputstream = request.getInputStream();
    这里不是已经说了, 看不懂?