Home » nio » Page 3

Tag Archives: nio

Java BufferedReader Example

In this example we are going to talk about BufferedReader Java class. BufferedReader is a subclass of Reader class. As you might know, Reader is a utility class for reading character streams. Such a stream could be obtained from a text file, from the console , from a socket, from a pipe , from a database or even from a ...

Read More »

java.io.FileInputStream – Java FileInputStream Example

In this example, we are going to see how to use FileInputStream in Java and inputstream. FileInputStream in an InputStream subclass that is used to read data from files in a file system. It is actually connected to a specific file and can be used to extract data from them and make them available inside your program for manipulation. As ...

Read More »

4 Ways to Copy File in Java

Although Java offers a class that can handle file operations, that is java.io.File, it doesn’t have a copy method that will copy a file to another. The copying action is an important one, when your program has to handle many file related activities. Nevertheless, there are several ways you can perform a file copying operation in Java and we will ...

Read More »

Convert Between Character Set Encodings with CharBuffer

In this example we shall show you how to convert between character set encodings with a CharBuffer in Java. To achieve character set conversions in Java one should perform the following steps: Use the Charset class to get the Charset object for utilizing the specific character set Use the newDecoder() API method of the Charset object to construct a new ...

Read More »

Convert String to byte array UTF encoding

With this example we are going to demonstrate how to convert a String to byte array and vice-versa using the default character encoding in Java. In short, to perform the aforementioned conversion, we are going to use classes from the NIO package in Java so as to convert every character from the target String to its byte equivalent. Namely we ...

Read More »

Create Stream from FileChannel

This is an example of how to create input and output streams to read and write data from/to a file in Java. Doing reads and writes of data using Java NIO Channels implies that you should : Create a File object to encapsulate an actual file in the file system To read data from the file you should create a ...

Read More »

Write to Channel with ByteBuffer

With this example we are going to demonstrate how to write data to a NIO Channel using a ByteBuffer in Java. In particular we are going to read data from a specific file in the file system and write them to a destination file. In short what we do is the following : To write data to a channel you ...

Read More »

Read from Channel with ByteBuffer

This is an example of how to read data from a NIO Channel using a ByteBuffer in Java. In particular we are going to read data from a specific file in the file system and print them on screen. In short what we do is the following : To read data from channel you should create a ReadableByteChannel. To do ...

Read More »

Create memory mapped file

This is an example of how to create a memory mapped file in Java. Doing reads and writes of data using Java NIO Channels implies that you should : Create a File object to encapsulate an actual file in the file system Create a random access file stream (read only, read-write). To do so you must first create a RandomAccessFile ...

Read More »