can someone explain this design decision?

It is because JSR 203 allows paths to be issued from more than one FileSystem, unlike File, which is always linked to the file system the JVM lives on. In JSR 203, this filesystem is called the default filesystem. You can get a reference to it using FileSystems.getDefault().

You use Paths.get() to get a path from the default filesystem, which is strictly equivalent to FileSystems.getDefault().getPath(). If you were to get a Path from another file system, you would use this particular file system's .getPath().

As a proof that a FileSystem can be for (nearly) anything, here are a few implementations over different sources:

  • in memory;
  • FTP;
  • SMB/CIFS;
  • Dropbox.

And there are a few others.

Answer from fge on Stack Overflow
🌐
HappyCoders.eu
happycoders.eu › java › how-to-construct-file-and-directory-names-with-file-path-paths
File and Directory Names in Java: File, Path, Paths
November 29, 2024 - File file = new File("dummy"); File absoluteFile = file.getAbsoluteFile(); File absoluteDirectory = absoluteFile.getParentFile();Code language: Java (java) Here we have generated a dummy file path, constructed the absolute path for it (which maps the file into the current directory), and then extracted the parent – the absolute path of the directory in which the file is located. Admittedly, this is rather cumbersome. Fortunately, there is a more elegant way: The current directory can also be read from a system property, user.dir, and then passed to the File constructor:
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Path.html
Path (Java Platform SE 8 )
April 21, 2026 - In the case of the default provider, the URI is hierarchical with a path component that is absolute. The query and fragment components are undefined. Whether the authority component is defined or not is implementation dependent. There is no guarantee that the URI may be used to construct a java.io.File.
🌐
Baeldung
baeldung.com › home › java › java io › java – path vs file
Java – Path vs File | Baeldung
April 20, 2024 - The Path class forms part of the NIO2 update, which came to Java with version 7. It delivers an entirely new API to work with I/O. Moreover, like the legacy File class, Path also creates an object that may be used to locate a file in a file system. Likewise, it can perform all the operations that can be done with the File class: ... Instead of using a constructor as we do with the File API, we create a Path instance using the static java.nio.file.Paths.get() method.
🌐
Medium
medium.com › javarevisited › understanding-the-java-nio-file-path-class-in-java-ff1b149b2d65
Understanding the java.nio.file.Path Class in Java | by WhatInDev | Javarevisited | Medium
January 19, 2025 - Discover the java.nio.file.Path class in Java for efficient, platform-independent file and directory path handling with practical examples and key methods.
🌐
Mkyong
mkyong.com › home › java › how to construct a file path in java
How to construct a file path in Java - Mkyong.com
October 23, 2014 - Some developers are using new File() API to construct the file path. ... package com.mkyong.file; import java.io.File; import java.io.IOException; public class FilePathExample2 { public static void main(String[] args) { try { String filename = "newFile.txt"; String workingDirectory = System.getProperty("user.dir"); //****************// File file = new File(workingDirectory, filename); //****************// System.out.println("Final filepath : " + file.getAbsolutePath()); if (file.createNewFile()) { System.out.println("File is created!"); } else { System.out.println("File is already existed!"); } } catch (IOException e) { e.printStackTrace(); } } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-nio-file-paths-class-in-java
java.nio.file.Paths Class in Java - GeeksforGeeks
March 12, 2021 - // Java program to demonstrate // java.nio.file.Path.get(URI uri) method import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Paths; public class Path { public static void main(String[] args) throws IOException, URISyntaxException { String uribase = "https://www.geeksforgeeks.org/"; // Constructor to create a new URI // by parsing the string URI uri = new URI(uribase); // create object of Path Path path = (Path)Paths.get(uri); // print ParentPath System.out.println(path); } } Output: https://www.geeksforgeeks.org/ Comment ·
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › nio › file › Path.html
Path (Java Platform SE 7 )
Paths associated with the default provider are generally interoperable with the java.io.File class. Paths created by other providers are unlikely to be interoperable with the abstract path names represented by java.io.File. The toPath method may be used to obtain a Path from the abstract path name represented by a java.io.File object.
Find elsewhere
🌐
O'Reilly
oreilly.com › library › view › java-for-dummies › 9781118239742 › a60_07_9781118239742-ch04.html
Path Interface - Java For Dummies Quick Reference [Book]
Because Path is an interface, not a class, it has no constructors. Of the many ways to create a Path object, one of the most common is to use the get method of the Paths class. For more information, see Paths Class.
🌐
TutorialsPoint
tutorialspoint.com › java_nio › java_nio_path.htm
Java NIO - Path
In order to get the instance of Path we can use static method of java.nio.file.Paths class get().This method converts a path string, or a sequence of strings that when joined form a path string, to a Path instance.This method also throws runtime InvalidPathException if the arguments passed contains illegal characters.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › java nio tutorial › java nio path
Java NIO Path | How to Create and Methods | Educba
June 29, 2023 - This is a guide to Java NIO Path. Here we discuss the introduction, how to create java NIO path class, methods and examples.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Jenkov
jenkov.com › tutorials › java-nio › path.html
Java NIO Path
The Java NIO Path interface represents a file system path to a file or directory. This Java NIO Path tutorial explains how to create Path instances, and how to work with them.
🌐
Gquintana
gquintana.github.io › 2017 › 09 › 02 › Java-File-vs-Path.html
Java File vs Path
To create a new Path instances, there is not constructor (Path is interface), we need to call a factory method.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Paths.html
Paths (Java Platform SE 8 )
April 21, 2026 - Java™ Platform Standard Ed. 8 ... This class consists exclusively of static methods that return a Path by converting a path string or URI.
🌐
Sololearn
sololearn.com › en › Discuss › 2487019 › what-do-you-mean-by-specifying-path-of-the-file-in-constructor-file-in-java
Update your browser
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Coderanch
coderanch.com › t › 403917 › java › relative-path-File-constructor
specify relative path in File constructor (Beginning Java forum at Coderanch)
June 21, 2006 - If I specify the absolute path, it works file like File F = new File("C:\\myFile","myFile.xml"); But if I want to access the file in the same folder and say File F = new File("myFile.xml"); It says file not found. How do I specify the file path without specifying the full path so that the code will be system independent.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › io › File.html
File (Java Platform SE 7 )
Otherwise an array of File objects ... included in the result. Each resulting abstract pathname is constructed from this abstract pathname using the File(File, String) constructor....
🌐
Baeldung
baeldung.com › home › java › java io › java nio2 path api
Java NIO2 Path API | Baeldung
January 8, 2024 - A Path object contains the file name and directory list used to construct the path and is used to examine, locate, and manipulate files. The helper class, java.nio.file.Paths (in plural form) is the formal way of creating Path objects.