Преимущества IO над NIO в java?

Прочитал, что nio лишь дополнение, а не замена io. Но тогда у пакета io должны быть свои преимущества? К примеру, в данном коде:

        // nio
        FileInputStream file = new FileInputStream("test.txt");
        FileChannel channel = file.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(128);
        while (channel.read(buffer) > 0){ }
        buffer.flip();
        while(buffer.hasRemaining()){
            System.out.print((char)buffer.get());
        }
        
        System.out.println();

        // io
       BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream("test.txt"));
        while (inputStream.available() > 0){
            System.out.print((char)inputStream.read());
        }

Также интересно - во всех статьях про Различие NIO и IO пишут,что в NIO есть буферизация,а в IO нет. Но как тогда с BufferedInputStream, к примеру?


Ответы (0 шт):