This one works for me:

return Path.of(ClassLoader.getSystemResource(resourceName).toURI());
Answer from keyoxy on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Path.html
Path (Java Platform SE 8 )
April 21, 2026 - java.nio.file · All Superinterfaces: Comparable<Path>, Iterable<Path>, Watchable · public interface Path extends Comparable<Path>, Iterable<Path>, Watchable · An object that may be used to locate a file in a file system. It will typically represent a system dependent file path.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Paths.html
Paths (Java Platform SE 8 )
April 21, 2026 - Converts the given URI to a Path object. This method iterates over the installed providers to locate the provider that is identified by the URI scheme of the given URI. URI schemes are compared without regard to case. If the provider is found then its getPath method is invoked to convert the URI.
🌐
Baeldung
baeldung.com › home › java › java io › java – path vs file
Java – Path vs File | Baeldung
April 20, 2024 - Since the very first versions, Java has delivered its own java.io package, which contains nearly every class we might ever need to perform input and output operations. The File class is an abstract representation of file and directory pathnames: ... Instances of the File class are immutable – once created, the abstract pathname represented by this object will never change. The Path class forms part of the NIO2 update, which came to Java with version 7.
🌐
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 - The java.nio.file.Path class is a cornerstone of the Java NIO (New Input/Output) package, introduced in Java 7. It provides an efficient way to represent and manipulate file and directory paths.
🌐
Java
download.java.net › java › early_access › panama › docs › api › java.base › java › nio › file › Paths.html
Paths (Java SE 19 & JDK 19 [build 1])
This method simply invokes Path.of(URI) with the given parameter. ... IllegalArgumentException - if preconditions on the uri parameter do not hold. The format of the URI is provider specific. FileSystemNotFoundException - The file system, identified by the URI, does not exist and cannot be created automatically, or the provider identified by the URI's scheme component is not installed
🌐
Medium
medium.com › @AlexanderObregon › javas-paths-get-method-explained-9586c13f2c5c
Java’s Paths.get() Method Explained | Medium
September 8, 2024 - Also, reserved characters and file naming conventions differ, which can lead to compatibility issues. By using Paths.get(), Java abstracts these differences, allowing us to focus on logic rather than platform-specific quirks, making it a important tool for making sure that file handling code works reliably across all environments.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-nio-file-paths-class-in-java
java.nio.file.Paths Class in Java - GeeksforGeeks
March 12, 2021 - Returns a Path by converting given strings into a Path. If "more" doesn't specify any strings than "first" is the only string to convert. If "more" specify extra strings then "first" is the initial part of the sequence and the extra strings ...
Top answer
1 of 1
3

java is emitting build\someFile.txt as you'd expect. To be specific, java emits a byte sequence to standard out which then goes on a trip. That goes into the OS, the OS sends it to whatever's hooked up to your java proces's standard out which at some point presumably takes those bytes, converts it back to a string, and then does something with that. Hopefully in this wild adventure eventually somewhere something turns it into a little picture of some characters and these, eventually, are rendered onto your screen, and from there, into your eyeballs.

Something in that wild adventure is applying backslash escaping. Terminals don't do it, so something else that you did not mention in your question is doing that. Java certainly doesn't do it. Something else is. If you just write this extremely basic:

class Test {
  public static void main(String[] args) throws Exception {
    Path x = Path.of("foo/bar.txt");
    System.out.println(x);
  }
}

and run that on a stock windows in a stock-standard windows cmd.exe terminal that prints foo\bar.txt as you'd expect.

Check the chain of apps that are in between the java process and your eyeballs. One of em is messing this up. If you need some help with this process, edit the question and explain in excruciating detail (because you probably don't know what's relevant, this mojibake / terminal stuff can be tricky like that) each and every app or thing that could possibly be in between. Are you running this within an IDE? Which one, and how. Are you running this on windows subsystem for linux? Mention that, how you're doing it, which commands you're typing in, and so on.

🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › java_nio › java_nio_path.htm
Java NIO - Path
As name suggests Path is the particular location of an entity such as file or a directory in a file system so that one can search and access it at that particular location. Technically in terms of Java, Path is an interface which is introduced in Java NIO file package during Java version 7,and is the representation of location in particular file system...
🌐
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.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › nio › file › Path.html
Path (Java SE 11 & JDK 11 )
January 20, 2026 - Package java.nio.file · All Superinterfaces: Comparable<Path>, Iterable<Path>, Watchable · public interface Path extends Comparable<Path>, Iterable<Path>, Watchable · An object that may be used to locate a file in a file system. It will typically represent a system dependent file path.
🌐
Android Developers
developer.android.com › sdk › api_diff › 34 › changes › java.nio.file.Path
java.nio.file.Path
JDiff is a Javadoc doclet which generates an HTML report of all the packages, classes, constructors, methods, and fields which have been removed, added or changed in any way, including their documentation, when two APIs are compared.
Top answer
1 of 1
2

Path is a class that represents a path. Anything where you typically already have a Path involves the methods located here.

Paths is a set of utilities. These utilities produce Path objects from other types of input. The utilities do not require having a Path ahead of time. They are convenience wrappers for common, often repeatedly used code, to reduce the need to cut-and-paste.

Here is an example of using Paths:

/* I have a String, but need a Path */
Path path = Paths.get("/home/user/.config");

Here is an example of using Path:

/* I have a Path, but need a String */
String name = path.toString();

The reason why a Utility class like Paths is required is a combination of a number of factors:

  1. Path is an interface, so direct calls of its constructor are not possible; as it has no constructor.
  2. String is a final class, and a class where modifying it would probably be far more difficult to present as an alternative than creating a utility class. So while "/home/user/.config".toPath() might be a valid object-oriented way of doing things, legacy code prevents adding that without more deliberation.
  3. URI has pressures on it similar to the pressures described above on String.

When they added in the NIO Path class, they wanted their code to be reviewed and integrated into the core Java library.

Stuff that is easy to get others to add to a library has the following characteristics:

  1. You don't mess with existing parts of the library in ways that are exposed by the established library call interface (doing this disrupts users of the library, as now they need to rewrite their programs).
  2. You have a backout plan that is easy (this is critical because you might not be able to deliver on time)

If they took the approach of modifying String and URI to have a getPath(...) function, then they would have increased the difficulty in getting their code integrated into the Java standard library.

🌐
Maven Central
central.sonatype.com
Maven Central
Official search by the maintainers of Maven Central Repository.
🌐
University of Edinburgh
inf.ed.ac.uk › teaching › courses › inf1 › op › 2020 › labs › NIO.html
Java File I/O (NIO.2)
Each of the Paths in these result lists will be relative to their respective directory. For example if oldDir is '/a/b', and the result list contains the file '/a/b/c/d', then the list will return that path as 'c/d'. An automated test has been created for this exercise: CompareDirectoriesTest.java.
🌐
Neo4j
neo4j.com › neo4j graph intelligence platform
Neo4j Graph Intelligence Platform
1 month ago - Connect data as it's stored with Neo4j. Perform powerful, complex queries at scale and speed with our graph data platform.