Home Tutorial Java Corejava Nio Java nio package - Learn how to use java nio package.

 
 

Share on Google+Share on Google+
Java nio package - Learn how to use java nio package.
Posted on: July 23, 2010 at 12:00 AM
Advertisement
In this section we will learn about the java.nio package.

Java nio package.

In this section we will learn about the java.nio package. We will also see how to use java.nio
package classes and its methods in java programming.

The java.nio (known as java new input output) package was introduced in Java 1.4 which is broadly 
used in data processing and it also provides better scalability. The benefits of using this is to read 
and write block of data rather byte by byte from the disk. The IO api works with byte streams 
and character stream but NIO api works wtih channel and buffers. A Java NIO FileChannel is 
used to connect to a file. Using a file channel you can read data from a file, and write data to 
a file. Data from channel is read into buffer and likewise it is written from a buffer to a channel.
 Java NIO Buffer is used when interacting with NIO Channels.

The java.nio package contains following abstract classes:

Buffer :
Buffer is basically a container for data of a specific primitive type which also is a linear and finite
sequence of elements. The other important properties of buffer are its capacity, limit and position
which are used while reading and writing into the buffer.

ByteBuffer :
The ByteBuffer class defines methods for reading and writing values of all primitive type (char, short,
int, long, and double) except the boolean type.

CharBuffer :
The Character Buffer is created either allocating space for buffer's content, by wrapping and existing
char array into a buffer or by creating a view of an existing byte buffer.

DoubleBuffer :
The Double Buffer is created either allocating space for buffer's content, by wrapping and existing
double array into a buffer or by creating a view of an existing byte buffer.

FloatBuffer :
The Float Buffer is created either allocating space for buffer's content, by wrapping and existing float
array into a buffer or by creating a view of an existing byte buffer.

IntBuffer :
The int Buffer is created either allocating space for buffer's content, by wrapping and existing int array
into a buffer or by creating a view of an existing byte buffer.

LongBuffer :
The long buffer is created either allocating space for buffer's content, by wrapping and existing long
array into a buffer or by creating a view of an existing byte buffer.

MappedByteBuffer :
The Mapped byte buffers is created with the map method of FileChannel class available in
java.nio.channels package. The contents of a mapped byte buffer can be changed at any time.
If the mapped file is truncated then all or part of a mapped byte buffer may be inaccessible at any
time.

ShortBuffer :
The short buffer is created either allocating space for buffer's content, by wrapping and existing
shortarray into a buffer or by creating a view of an existing byte buffer.

Now we will see examples on java.nio package and how it is implemented in java programming.

How to get bytes from ByteBuffer in java.
In this tutorial you will see how to get bytes from ByteBuffer in java.
 
How to get the capacity of ByteBuffer in java.
In this tutorial you will see how to get the capacity of ByteBuffer in java.
 
How to compute limit of ByteBuffer in java.
In this tutorial you will see how to compute limit of ByteBuffer in java.
 
Use of rewind method in java.
In this tutorial you will see use of rewind method in java.
 
How to clean a buffer using clear method in java.
In this tutorial you will see how to clean a buffer using clear method in java.
 
Order bytes from most significant to least significant.
In this tutorial you will learn about how to order bytes from most significant to least significant.
 
Order bytes from least significant to most significant.
In this tutorial you will learn about how to order bytes from least significant to most significant.
 
Compare two buffer's content
In this tutorial you will learn about how to compare two buffer's content
 
Get the capacity of a buffer
In this tutorial you will learn about how get the capacity of a buffer
 
How to Create a ByteBuffer using Byte Array in java.
In this tutorial you will see how to Create a ByteBuffer using Byte Array in java.
 
How to transfer data from ByteBuffer to byte array in java.
In this tutorial you will see how to transfer data from ByteBuffer to byte array in java.
 
How to get specific index value from ByteBuffer in java.
In this tutorial you will see how to get specific index value from ByteBuffer in java.
 
Use of getChar method of ByteBuffer Class in java.
In this tutorial you will see the use of getChar method of ByteBuffer Class in java.
 
Place array of bytes in buffer
In this tutorial you will see how to place array of bytes in buffer.
 
Wraps a character array into a buffer
In this tutorial you will see how to wraps a character array into a buffer.
 
Wraps a character sequence into a buffer.
In this tutorial you will see how to wraps a character sequence into a buffer.
 
Writes the given character into buffer at the given index.
In this tutorial you will see how to write the given character into buffer at the given index.
 
Creates a view of byte buffer as a char buffer.
In this tutorial you will see how to creates a view of byte buffer as a char buffer.
 
Creates a view of this byte buffer as a double buffer.
In this tutorial you will see how to creates a view of this byte buffer as a double buffer.
 
How to write the given byte into byte buffer.
In this tutorial you will see how to write the given byte into byte buffer.
 
Writes the given character into buffer at the given index.
In this tutorial you will see how to write the given character into buffer at the given index.
 
Creates a view of byte buffer as a char buffer.
In this tutorial you will see how to creates a view of byte buffer as a char buffer.
 
Creates a view of this byte buffer as a double buffer.
In this tutorial you will see how to creates a view of this byte buffer as a double buffer.
 
How to write the given byte into byte buffer.
In this tutorial you will see how to write the given byte into byte buffer.
 
Get the limit position and capacity of a character buffer.
In this tutorial you will see how to get the limit position and capacity of a character buffer.
 
Compare buffer to another object.
In this tutorial you will see how to compare buffer to another object.
 
Reads the character at buffer's current position.
In this tutorial you will see how to read the character at buffer's current position.
 
Check for any elements exists between the current position and the limit of a buffer.
In this tutorial you will see how to check for existence of any element between the current position and the limit of a buffer.
 
Creates a view of  byte buffer as a float buffer.
In this tutorial you will see how to creates a view of  byte buffer as a float buffer.
 
Write a byte into byte buffer at given index.
In this tutorial you will see how to write a byte into byte buffer at given index.
 
Compare two double type buffer's content
In this tutorial we will see how to compare two double type buffer's content
 
Get the capacity of a double type buffer
In this tutorial we will see how to get the capacity of a double type buffer
 
Place array of double in a buffer
In this tutorial you will see how to place array of double in buffer.
 
Wraps a double type array into a buffer
In this tutorial you will see how to wraps a double array into a buffer.
 
Writes the given double value into a buffer at the given index.
In this tutorial you will see how to write the given double into buffer at the given index.
 
Get the limit position and capacity of a double type buffer.
In this tutorial you will see how to get the limit position and capacity of a character buffer.
 
Compare a double type buffer to another object
In this tutorial you will see how to compare double buffer to another object.
 
Check for any elements exists between the current position and the limit of a double type buffer.
In this tutorial you will see how to check for existence of any element between the current position and the limit of a buffer.
 
Check for number of elements exists between the current position and the limit of a double type buffer.
In this tutorial you will see how to check for existence of any element between the current position and the limit of a double buffer.
 
Creates a view of  byte buffer as a int buffer.
In this tutorial you will see how to creates a view of byte buffer as a int buffer.
 
Creates a view of  byte buffer as a long buffer.
In this tutorial you will see how to create a view of byte buffer as a long buffer.
 
Use of getInt() method of ByteBuffer class in java.
In this tutorial you will see the use of getInt() method of ByteBuffer class in java.
 
Use of isDirect() method of byte buffer class in java.
In this tutorial you will see the use of isDirect() method of ByteBuffer class in java.
 
Use of putDouble() and getDouble() method of ByteBuffer class.
In this tutorial you will see the use of putDouble() and getDouble() method of ByteBuffer class.
 
Use of hasArray() method of ByteBuffer class in java.
In this tutorial you will see the use of hasArray()method of ByteBuffer class in java.
 
Use of equals() method of ByteBuffer class in java.
In this tutorial you will see the use of equals() method of ByteBuffer class in java.
 
Use of getFloat() method of ByteBuffer class in java.
In this tutorial you will see the use of getFloat() method of ByteBuffer class in java.
 
Use of putChar() method of ByteBuffer class.
In this tutorial you will see the use of putChar() method of ByteBuffer class.
 
How to allocate a float buffer in java.
In this tutorial you will see how to allocate a float buffer in java.
 
Use of rewind() method of FloatBuffer class.
In this tutorial you will see the use of rewind method of FloatBuffer class..
 
Use of hasRemaining() method in float buffer class.
In this tutorial you will see the use of hasRemaining() method in FloaBuffer class.
 
Create a float buffer by using wrap method of FloatBuffer class.
In this tutorial you will see how to create a float buffer by using wrap method of FloatBuffer class.
 
Use of array() method of FloatBuffer class in java.
In this tutorial you will see the use of array() method of FloatBuffer class in java.
 
Transfer the content of a float buffer into another float buffer.
In this tutorial you will see how to transfer the content of a float buffer into another float buffer.
 
Creates a read-only float buffer that shares the content of float buffer.
In this tutorial you will see how to creates a read-only float buffer that shares the content of float buffer.
 
Creates a duplicate float buffer that shares the content of float buffer.
In this tutorial you will see how to create a duplicate float buffer that shares the content of float buffer.
 
Use of equals() method of  FloatBuffer class in java.
In this tutorial you will see use of equals() method of  FloatBuffer class in java.
 
Compare a float buffer with another float buffer.
In this tutorial you will see how to compare a float buffer with another float buffer.
 
Transfer the content of a float buffer into float array.
In this tutorial you will see how to transfer the content of a float buffer into float array.
 
Transfer the content of a float array into float buffer.
In this tutorial you will see how to transfer the content of a float array into float buffer.
 
How to get given index value from FloatBuffer in java.
In this tutorial you will see how to get given index value from FloatBuffer in java.
 
Write a float value into float buffer at given index.
In this tutorial you will see how write a float value into float buffer at given index.
 
Use of hasCode method of FloatBuffer class in java.
In this tutorial you will see the use of hashCode method of FloatBuffer class in java.
 
Use of slice method of FloatBuffer class in java.
In this tutorial you will see the use of slice method of FloatBuffer class in java.
 
How to clear a float buffer in java.
In this tutorial you will see how to clear a float buffer in java.
 
Use of toString() method of FloatBuffer class.
In this tutorial you will see the use of toString() method of FloatBuffer class.
 
How to rewind float buffer in java.
In this tutorial you will see how to rewind float buffer in java.
 
How to allocate a new int buffer in java.
In this tutorial you will see how to allocate a new int buffer in java.
 
Create a int buffer by wrapping an int array into a buffer.
In this tutorial you will see how to create a int buffer by wrapping an int array into a buffer.
 
How to create a int buffer with the help of byte buffer.
In this tutorial you will see how to create a int buffer with the help of byte buffer.
 
Create a int array with the help of int buffer.
In this tutorial you will see how to create a int array with the help of int buffer.
 
Creates a read-only int buffer that shares the content of int buffer.
In this tutorial you will see how to creates a read-only int buffer that shares the content of int buffer.
 
Compare a int buffer with another int buffer.
In this tutorial you will see how to compare a int buffer with another int buffer.
 
Creates a duplicate int buffer that shares the content of int buffer.
In this tutorial you will see creates a duplicate int buffer that shares the content of int buffer.
 
Use of equals() method of IntBuffer class in java.
In this tutorial you will see the use of equals() method of IntBuffer class in java.
 
How to read all value from int buffer in java.
In this tutorial you will see how to read all value from int buffer in java.
 
How to get specific index value from int buffer.
In this tutorial you will see how to get specific index value from int buffer.
 
How to transfer data from int buffer to int array.
In this tutorial you will see how to transfer data from int buffer to int array.
 
Use of isDirect() method of intBuffer class in java.
In this tutorial you will see the use of isDirect() method of intBuffer class in java.
 
Transfer the content of a int array into int buffer.
In this tutorial you will see how to transfer the content of a int array into int buffer.
 
Transfer the content of a int buffer into another int buffer.
In this tutorial you will see how to transfer the content of a int buffer into another int buffer.
 
Write a int value into int buffer at given index.
In this tutorial you will see how to write a int value into int buffer at given index.
 
Calculate total number of elements remaining in the buffer.
In this tutorial you will see how to calculate total number of elements remaining in the buffer.
 
How to rewind the int buffer in java.
In this tutorial you will see how to rewind the int buffer in java.
 
How to clear int buffer in java.
In this tutorial you will see how to clear int buffer in java.
 
Use of isReadOnly() method in java.
In this tutorial, you will see the use of isReadOnly() method in java.
 
How to allocate a new long buffer in java.
In this tutorial, you will see how to allocate a new long buffer in java.
 
Create a long buffer by wrapping an long array.
In this tutorial, you will see how to create a long buffer by wrapping an long array.
 
How to create a long buffer with the help of byte buffer.
In this tutorial, you will see how to create a long buffer with the help of byte buffer.
 
How to create a long array with the help of long buffer.
in this tutorial, you will see how to create a long array with the help of long buffer.
 
How to create a read-only long buffer in java.
In this tutorial, you will see how to create a read-only long buffer in java.
 
How to get specific index value from long buffer.
In this tutorial, you will see how to get specific index value from long buffer.
 
How to transfer value from long buffer to long array.
In this tutorial, you will see how to transfer value from long buffer to long array.
 
How to check long buffer is direct or not in java.
In this tutorial, you will see how to check long buffer is direct or not in java.
 
Use of hashCode() method of LongBuffer class in java.
In this tutorial, you will see the use of hashCode() method of LongBuffer class in java.
 
How to create a duplicate buffer of a long buffer in java.
In this tutorial, you will see how to create a duplicate buffer of a long buffer in java.
 
Check long buffer is read_only or not.
In this tutorial, you will see how to check long buffer is read_only or not.
 
Write a long value at given index into long buffer.
In this tutorial, you will see how to write a long value at given index into long buffer.
 
How to transfer the value of a long  array into long buffer.
In this tutorial, you will see how to transfer the value of a long  array into long buffer.
 
How to transfer the content of a long buffer into another long buffer.
In this tutorial, you will see how to transfer the content of a long buffer into another long buffer.
 
Compare a long buffer with another long buffer.
In this tutorial, you will see how to compare a long buffer with another long buffer.
 
Use of equals() method of LongBuffer class in java.
In this tutorial, you will see the use of equals() method of LongBuffer class in java.
 
How to create a short buffer with the help of byte buffer.
In this tutorial, you will see how to create a short buffer with the help of byte buffer.
 
How to allocate a short buffer in java.
In this tutorial, you will see how to allocate a short buffer in java.
 
Create a short buffer by using wrap method of ShortBuffer class.
In this tutorial, you will see how to create a short buffer by using wrap method of ShortBuffer class.
 
Create a short array with the help of short buffer.
In this tutorial, you will see how to create a short array with the help of short buffer.
 
Create a duplicate short buffer that shares the content of a short buffer.
In this tutorial, you will see how to create a duplicate short buffer that shares the content of a short buffer.
 
How to get specific index value from short buffer.
In this tutorial, you will see how to get specific index value from short buffer.
 
ShortBuffer in java, Use of toString() method of ShortBuffer class.
In this tutorial, you will see the use of toString() method of ShortBuffer class.
 
ShortBuffer in java, Create a read-only short buffer that shares the content of short buffer.
In this tutorial, you will see how to create a read-only short buffer that shares the content of short buffer.
 
ShortBuffer in java, Compare a short buffer with another short buffer.
In this tutorial, you will see how to compare a short buffer with another short buffer.
 
ShortBuffer in java, Use of equals() method of ShortBuffer class in java.
In this tutorial, you will see how to use of equals() method of ShortBuffer class in java.
 
ShortBuffer in java, Clean a short buffer by using clear method.
In this tutorial, you will see how to clean a short buffer by using clear method.
 
ShortBuffer in java, Use of isDirect() method of ShortBuffer class in java.
In this tutorial, you will see how to use of isDirect() method of ShortBuffer class in java.
 
ShortBuffer in java, Write a short value into short buffer at given index.
In this tutorial, you will see how to write a short value into short buffer at given index.
 
ShortBuffer in java, How to transfer content from short buffer to short array.
In this tutorial, you will see how to transfer content from short buffer to short array.
 
 ShortBuffer in java, Transfer the array's elements into short buffer.
In this tutorial, you will see how to transfer the array's elements into short buffer.
 
ShortBuffer in java, Use of slice method of ShortBuffer class.
In this tutorial, you will see the use of slice method of ShortBuffer class.
 
ShortBuffer in java, Transfer the content of a short buffer into another.
In this tutorial, you will see how to transfer the content of a short buffer into another.
 
ShortBuffer in java, How to rewind a short buffer in java.
In this tutorial, you will see how to rewind a short buffer in java.
 
Java MappedByteBuffer example, How to create mapped byte buffer in java.
In this tutorial, you will see how to create mapped byte buffer in java.
 
Java MappedByteBuffer example, How to create a large size file in java.
In this tutorial, you will see how to create a large size file in java.
 
ShortBuffer in java, Use of hasRemaining() method in short buffer.
In this tutorial, you will see the use of hasRemaining() method in short buffer.
 
ShortBuffer in java, How to reset the mark of short buffer.
In this tutorial, you will see how to reset the mark of short buffer.
 
ShortBuffer in java, Use of remaining() method in short buffer.
In this tutorial, you will see use of remaining() method in short buffer.
 
ShortBuffer in java, Use of hashCode() in short buffer.
In this tutorial, you will see the use of hashCode() in short buffer.
 
ShortBuffer in java, Define the order of byte in short buffer.
In this tutorial, you will see how to define the order of byte in short buffer.
 
Advertisement

Related Tags for Java nio package - Learn how to use java nio package.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 23, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com