Book Image

Java 7 New Features Cookbook

By : Richard M. Reese, Jennifer L. Reese
Book Image

Java 7 New Features Cookbook

By: Richard M. Reese, Jennifer L. Reese

Overview of this book

<p>Java 7 is a major update that includes a lot of exciting new language improvements such as support for type inference and improved exception handling. Other new features include the ability to work with symbolic links, a greatly simplified directory traversal technique, and the monitoring of file creation and deletion. Improvements in event handling, security, and concurrent processing have also been added<br /><br />Java 7 New Features Cookbook is your go-to guide to learn about all the new exciting features Java 7 has to offer with a very practical recipe-based approach. <br /><br />The book starts with coverage of the new language improvements. Subsequent chapters address the new features of Java 7 while incorporating these new language improvements when possible.<br /><br />The new NIO techniques provide enhanced capabilities which are complemented by the new try-with-resources block and enhanced generic support. The new JLayer decorator and improved window methods enhance the developer&rsquo;s ability to create GUI applications. <br /><br />The Java 7 New Features Cookbook provides a comprehensive coverage of the exciting features in Java 7.</p>
Table of Contents (18 chapters)
Java 7 New Features Cookbook
Credits
About the Authors
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

Obtaining a map of file attributes


An alternative way of accessing file attributes is to use the Files class' readAttributes method. There are two overloaded versions of this method, and they differ in their second argument and their return data types. In this recipe, we will explore the version that returns a java.util.Map object as it allows more flexibility in what attributes it can return. The second version of the method is discussed in a series of recipes, each devoted to a specific class of attributes.

Getting ready

To obtain a list of attributes in the form of a Map object, the following steps need to be done:

  1. 1. Create a Path object representing a file.

  2. 2. Apply the static readAttributes method against the Files class.

  3. 3. Specify the value of its arguments:

    • The Path object representing the file of interest

    • A String argument representing the attributes to be returned

    • An optional third argument specifying whether symbolic links should be followed or not

How to do it...

  1. 1. Create a new console...