In this section we will discuss about the Java IO Path.
Storage of a file or folder(Directory/Subdirectory) in a Hard Drive or other media is called a Path of that file or folder using which they can be accessed easily. Mostly files systems follows the tree structure to store the file. As the tree structure is defined there can be one or more root nodes. In the perspective of Microsoft Windows there can be a file or sub folders under a root folder. These sub folders can contains a file or sub folders and so on. For example an image is given below :
So, according to the above image the path (in windows) of the file xyz.text file will be as follows :
In the above file path the character ' \ ' is a directory separator also called the delimiter. The file separator varies from O/S to O/S for example the Microsoft Windows uses the ' \ ' (backslash) whereas, the Solaris OS uses the ' / ' (forward slash).
Now there can be two types of path either 'relative' or 'absolute'.
Absolute Path : Path for locating a file uses the complete directory path from root node to file is an absolute path. for example, to locate a xyz.txt file in the above image the absolute path will be C:\user\user2\xyz.txt
Relative Path : A relative path does not contains the complete directory path from root node to the file which has to be located. for example, to locate a xyz.txt file in the above image the relative path will be \user2\xyz.txt. The relative path is unreliable to locate the file without complete information.
To work with Path in Java, the Path class is provided about which we will discussed in our next tutorial.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial