java.nio


1. Reading a File into a Buffer

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.nio.ByteBuffer;

public class ReadFile {

    public static void main(String[] args) throws Exception {
        // Create a new buffer to hold the contents of the file
        ByteBuffer buffer = ByteBuffer.allocate(1024);

        // Read the file into the buffer
        int bytesRead = Files.read(Paths.get("file.txt"), buffer);

        // Create a new byte array to hold the data from the buffer
        byte[] data = new byte[bytesRead];

        // Copy the data from the buffer to the array
        buffer.flip();
        buffer.get(data);

        // Print the data from the array
        System.out.println(new String(data));
    }
}

2. Writing to a File from a Buffer

3. Creating a Direct Buffer

4. Using a MappedByteBuffer

5. Using a FileChannel

6. Using a CharBuffer

7. Using a DoubleBuffer

8. Using a FloatBuffer

9. Using an IntBuffer

10. Using a LongBuffer

11. Using a ShortBuffer

12. Using a Buffer

13. Using a BufferArray

14. Using a HeapByteBuffer

15. Using a ByteBufferAsCharBuffer

16. Using a CharBufferAsByteBuffer

17. Using a DoubleBufferAsByteBuffer

18. Using a FloatBufferAsByteBuffer

19. Using an IntBufferAsByteBuffer