Posts

Showing posts with the label nio

Java 7 Working With Directories: DirectoryStream, Filter and PathMatcher

My previous post was about Java 7's new java.nio.file.Path class  this time I want to continue and explorer some of the other new file system related APIs in Java 7. java.nio.file.DirectoryStream DirectoryStream provides an easy way to iterate over directories content, but more than that it introduces a solution for a long existing problem of listing within very large directories. If I wanted to list folder entries using previous Java versions I had to use one of the java.io.File's list() or listFiles() overloaded methods: // Pre Java 7 Directory Listing Example File f = new File("c:/tmp"); String[] names = f.list(); // At this point Java listed all files in c:/tmp and loaded their names into an array of Strings for (String name : names) { System.out.println(name); } The problem with the old API is that once I asked a File object to list its entries it would immediately scan the folder creating an array of strings (or file objects if l...

Java 7 - Path Manipulation Using java.nio.file.Path

Lately I had the feeling it's about time to starts looking into Java 7 EA, it has been under development for some time now and by the latest news it should be released soon. So I downloaded JDK 7-EA and Netbeans 7 (Eclipse doesn't support Java 7 language changes yet) and looked for interesting changes in the release notes, the first few I've noticed are the I/O enhancements on which I decided to write a post or two starting with a short coverage of the new APIs for path manipulation in the new java.nio.file.Path interface.