When constructing an object that will be shared between threads, be very careful that a reference to the object does not "leak" prematurely. For example, suppose you want to maintain a List called instances containing every instance of class. You might be tempted to add the following line to your constructor:
But then other threads can use instances to access the object before construction of the object is complete.
The toRealPath method returns the real path of an existing file. This method performs several operations in one:
If true is passed to this method and the file system supports symbolic links, this method resolves any symbolic links in the path.
If the Path is relative, it returns an absolute path.
If the Path contains any redundant elements, it returns a path with those elements removed.
Note that if there is an exception during directory iteration then DirectoryIteratorException is thrown with the IOException as the cause. Iterator methods cannot throw exception exceptions.