我使用下面的方法来写InputStream到File:
private void writeToFile(InputStream stream) throws IOException {
    String filePath = "C:\\Test.jpg";
    FileChannel outChannel = new FileOutputStream(filePath).getChannel();       
    ReadableByteChannel inChannel = Channels.newChannel(stream);
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    while(true) {
        if(inChannel.read(buffer) == -1) {
            break;
        }
        buffer.flip();
        outChannel.write(buffer);
        buffer.clear();
    }
    inChannel.close();
    outChannel.close();
}
我想知道这是否是使用NIO的正确方法.我读过一个方法FileChannel.transferFrom,它有三个参数:
在我的情况下,我只有src,我没有position和count,有什么办法可以使用这种方法来创建文件?
另外对于Image有没有更好的方法来创建只有InputStreamNIO的图像?
任何信息对我都非常有用.这里有类似的问题,在SO中,但我找不到适合我的案例的特定解决方案.