We all are familiar with reading/writing file in a synchronous way. In Java 7 a new API was added to read/write the contents of the file asynchronously. The API is AsynchronousFileChannel. In this example lets look at how to read the contents of the file asynchronously. There are two approaches to read the contents asynchronously: [...]
Archive | Java 7.0 RSS feed for this section
Visiting all the files and directories for a directory in Java using NIO2
July 22, 2012
At times we might want to search for some file in a directory traversing recursively into other directories with in that directory, I know getting the recursive program right at the first time is always a challenge. Or we might want to list all the contents of a directory. For all these operations the NIO2 [...]
Listing and filtering directory content using Java NIO2
July 20, 2012
The Files class provides a method- newDirectoryStream to get the Directory contents for a give path instance. There are other overloaded versions of newDirectoryStream method which take in filters to apply on the directory content. Listing all files in the directory Using Files.newDirectoryStream method gives an instance of DirectoryStream class which is a Iterable i.e [...]
Creating Hard links and Soft links for a file in Java
July 17, 2012
We have been exploring the NIO enhancements in Java 7 and in this post I will explain about creating links- Hard links and Soft links in Java. And this feature is part of Java 7. A link is kind of substitute name to access a particular file/directory, something like an alias to the file/directory. This [...]
Obtaining and modifying the metadata of the files in Java 7 NIO.2
July 13, 2012
Files usually contain information like its creation time, last modified time, last accessed time, size, type, permissions, ownership and other details which constitute its metadata. NIO.2 enhancements in Java 7 adds views to obtain metadata information of the file. The file attributes are grouped into different views based on their relatedness and applicability, for example [...]
Exploring the Path API – Java NIO enhancement in Java 7
July 12, 2012
All of us know that an instance of File doesn’t indicate a file in the file system, unless some one invokes a create or related methods. But its a kind of confusion- you talk about instance of File and then you also talk about file at the disk level. A new class was introduced in [...]
Creating, Writing, Reading files using Java Files API of Java 7
June 20, 2012
In our previous post we did get a taste of the power of the static APIs in the Java Files class and we managed to compare the code written without using the APIs in Java Files and with using the APIs in Java Files. In this post let me delve further into the other APIs [...]
A peek into the Files utility which is part of java.nio package in Java 7
June 18, 2012
We recently wrote about watching a directory using the new APIs introduced as part of Java 7. In this post let me throw some light on another class added to the java.nio package as part of Java 7 update- java.nio.file.Files. Another piece of information related to this is that complete java.nio.file package was added as [...]
Implementing WatchService API in Java 7 to monitor the directory changes
June 15, 2012
In Java 7 there were quite a lot of new things added to the File NIO package (java.nio)- there was a new java.nio.file package and java.nio.file.attribute package. Main highlights of the java.nio.file package are the following classes: Path: Its an object used to locate a file or directory in the file system. The value contained [...]
Merge Sort implementation using Fork-Join Framework in Java 7
June 13, 2012
In our previous post we went through the basics of Fork-Join Framework introduced as part of Java 7. In this post lets apply the same Fork-Join to implement Merge sort algorithm. The pseudo code for Merge sort can be found here. In summary the Merge sort algorithm: 1. Divides the array into 1 parts 2. [...]






August 22, 2012
2 Comments