DEV Community

Cover image for Java Quickies. Paths
Tristan Elliott
Tristan Elliott

Posted on • Edited on

Java Quickies. Paths

Introduction

  • This series is going to be dedicated to the basic understanding of Java. When ever I find myself asking, "How does this work ?". I will create a blog post and put it here. This series will not be in order so feel free to read what ever post you find most relevant.

What is a path?

  • In Java a path is a class and as the name implies, the path is a programmatic representation of a path in your file system.

  • A Path instance reflects the underlying platform. In Windows the path object uses the Windows syntax(C:\home\joe\foo). Your path may look different depending on your underlying operating system.

  • A Path is not system independent, you can not compare a path from two different operating systems and expect them to reach the same directory.

  • A Path object represents a path that is hierarchical and composed of a sequence of directory and file name elements. These elements are separated by a special separator called a delimiter. A Path object also contains a root component, that identifies the file system's hierarchy. The name of the element that we are accessing is the one farthest from the root directory(cat)

C:\foo\pie\cat
Enter fullscreen mode Exit fullscreen mode
  • The above code is an example of a path in the Windows environment. The "C:" is the root directory in Windows and it represents our C-drive, which is the main hard drive. The backslashes are examples of the delimitators and are used as a form of separation. cat is the element that we are accessing.

Conclusion

  • Thank you for taking the time out of you day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.
  • Also make sure to checkout my YouTube channel for more programming tutorials.

Top comments (0)