Home » filechannel

Tag Archives: filechannel

Java write to File Example

In this post, we feature a comprehensive example of how to write to File in Java using FileWriter, FileOutputStream, and NIO. We are going to investigate several methods to write a File in Java. We will list some of the older, before Java 7 and NIO, methods to write to a text or a binary file as well as some ...

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 »

Copying binary file with FileChannel

With this example we demonstrate how to copy files using FileChannels in Java. In particular we are going to read data from a specific file in the file system and write them to another file. In short what we do is the following : For the source file we create a FileChannel so as to be able to read data ...

Read More »