Home » Core Java » nio » FileChannel

FileChannel

java.nio.channels.FileChannel Example

This article introduces the FileChannel class and its basic usage. This class is available since Java 1.4 as part of Java NIO (New IO) File API. This article shows reading from and writing to file using file channels. The examples in this article are compiled and run in Windows OS environment. Note that Java SE 7 is required to run ...

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 »

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 »