Listing and filtering directory contents in NIO.2

There hasn’t been much happening in the area of listing directory contents until the release of Java 7. But since NIO.2 introduced a new way to do this it might be worth it to cover this area. One of big pluses of NIO.2 is the ability to use listing and filtering at once in one method call. This provides an elegant solution to most of listing/filtering needs related to work with a file system.

Continue reading “Listing and filtering directory contents in NIO.2”

Creating files and directories in NIO.2

Great number of applications nowadays create files or directories for very wide range of purposes. Whether it is to generate a report, export piece of configuration or simply to store some data it is important to be able to handle these tasks. Creating files and directories is one of the most heavily used functionality while working with a file system. This part of library underwent quite a modernization. Updates in this area include guarantee of atomicity of certain operations, creation of files and directories with preset file attributes, performance optimization as well as introduction of exception hierarchy that replaced boolean returning methods from prior versions of IO library.

Continue reading “Creating files and directories in NIO.2”

Master your IDE logging with Grep console

One of many daily activities that every programmer needs to do in order to do their work is to control logging output from their application. Logging, when done properly and correctly, provides great insight into the inner workings of the application and may be a great resource for analyzing and optimizing your codes behavior. Whether it is during development or maintenance/support phase of the product life-cycle, this task is often considered to be unpleasant for many programmers. But since log analysis is so important and often required there usually isn’t simple way around. In this article I will present an elegant solution to reviewing logs in development stage of the application within IDE.

Continue reading “Master your IDE logging with Grep console”

Paths in NIO.2

In order to work with file system one must first be able to point to files and directories. The first thing that needs to be understood is the role of java.nio.file.Path class, the way instances are created and its functionality. As mentioned in previous articles, Path is just an abstraction of the file system location. This allows for the situations when directory does not even have to exist. NIO.2 presents more elegant solutions for getting the object representing file system location. This shields programmer from platform specific problems.

In general, Path instances allow two types of operations:

  • syntactic operations
    • any operations related to the Path representation itself – hierarchy traversal, conversion, comparison and so on
  • file operations
    • operations that modify location, state or contents of a file represented by a path instance

Continue reading “Paths in NIO.2”