java.lang.Object
com.aoapps.io.filesystems.Path
All Implemented Interfaces:
Comparable<Path>
Direct Known Subclasses:
FileSystemWrapper.PathWrapper

public class Path extends Object implements Comparable<Path>
The object representing the path to a file. This API is for programmer tools, not for user interfaces. We try to hide the platform differences.

As there is no concept of "working directory" in this API, the path is always absolute. However, the path may be interpreted from a different effective root by a file system.

Each file system may limit the length of path names or total paths, but there is no limit imposed within Path itself.

The path separator is always "/", even on platforms that do otherwise.

The root path is an empty string (and the only path name that may be an empty string). In string form, the root path by itself is represented as "/".

Paths are case-sensitive, even on platforms that do otherwise.

Author:
AO Industries, Inc.
  • Field Details

    • SEPARATOR

      public static final char SEPARATOR
      See Also:
    • SEPARATOR_STRING

      public static final String SEPARATOR_STRING
  • Constructor Details

  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      See Also:
    • equals

      public boolean equals(Path other)
      Two paths are equal if they are of the same depth and have equal names. Two paths on different file systems can be equal.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(Path other)
      Compares two paths in lexical order.
      Specified by:
      compareTo in interface Comparable<Path>
    • toString

      public String toString()
      Gets a string representation of the path. The root is the separator by itself ("/").
      Overrides:
      toString in class Object
      See Also:
    • toString

      public void toString(Appendable out) throws IOException
      Gets a string representation of the path. The root is the separator by itself ("/").
      Throws:
      IOException
      See Also:
    • getFileSystem

      public FileSystem getFileSystem()
      Gets the file system this path belongs to and is valid for.
    • getParent

      public Path getParent()
      Gets the parent of this path. Only the root will have a null parent.
    • getName

      public String getName()
      Gets the name of this part of the path.
    • getDepth

      public int getDepth()
      Gets the depth of this path. The root has a zero depth. This is also the number of non-root names in this path, such as the number of elements that will be returned from explode().
      See Also:
    • explode

      public String[] explode()
      Explodes this path into a set of names, not including the empty root name itself. The root path is represented by an empty array.
      See Also:
    • explode

      public String[] explode(String[] names)
      Explodes this path to the given array. If the array is not filled, the element one past the last name will be set to null.
      Returns:
      the array parameter
      Throws:
      ArrayIndexOutOfBoundsException - if the provided array is of insufficient length
      See Also: