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 } }
我要的不是文件流 我要的是从request对象里面获得的数据流
FileOutputStream fos = new FileOutputStream(f); // replace with InputStream inputstream = request.getInputStream(); 这里不是已经说了, 看不懂?
没用过呢,
这么冷清
帮兄弟顶一下!
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
}
}
我要的是从request对象里面获得的数据流
这里不是已经说了, 看不懂?