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.

Answer from rzwitserloot on Stack Overflow
🌐
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.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › nio › file › Paths.html
Paths (Java SE 11 & JDK 11 )
January 20, 2026 - java.nio.file.Paths · public final class Paths extends Object · This class consists exclusively of static methods that return a Path by converting a path string or URI. API Note: It is recommended to obtain a Path via the Path.of methods instead of via the get methods defined in this class ...
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › nio › file › class-use › Path.html
Uses of Interface java.nio.file.Path (Java SE 11 & JDK 11 )
October 20, 2025 - Report a bug or suggest an enhancement For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › › java.base › java › nio › file › package-summary.html
java.nio.file (Java SE 11 & JDK 11 )
October 20, 2025 - The File class defines the toPath method to construct a Path by converting the abstract path represented by the java.io.File object. The resulting Path can be used to operate on the same file as the File object.
🌐
Dariawan
dariawan.com › tutorials › java › java-11-new-methods-path-and-files
Java 11 - New Methods in Path and Files | Dariawan
February 25, 2019 - Path of(net.URI): Returns a Path by converting a URI. ... package com.dariawan.file; import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; public class PathOf { public static void main(String[] args) throws IOException { String tempFolder = System.getProperty("java.io.tmpdir"); // Create Path from a sequence of Strings Path path1 = Path.of(tempFolder, "test.txt"); System.out.println(path1); System.out.println(Files.exists(path1)); File file = new File(path1.toString()); //Create the file if (file.createNewFile()) { System.o
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.

🌐
GitHub
github.com › JetBrains › jdk8u_jdk › blob › master › src › share › classes › java › nio › file › Path.java
jdk8u_jdk/src/share/classes/java/nio/file/Path.java at master · JetBrains/jdk8u_jdk
package java.nio.file; · import java.io.File; import java.io.IOException; import java.net.URI; import java.util.Iterator; · /** * An object that may be used to locate a file in a file system. It will · * typically represent a system dependent file path.
Author   JetBrains
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.nio.filenio.path.of
Path.Of Method (Java.Nio.FileNio) | Microsoft Learn
The default provider provides a ... java.io.File class. For a given Pathp it is guaranteed that <blockquote>Path.of(p.Path#toUri() toUri()).equals(p.Path#toAbsolutePath() toAbsolutePath())</blockquote> so long as the original Path, the URI, and the new Path are all created in (possibly different invocations of) the same Java virtual machine. Whether other providers make any guarantees is provider specific and therefore unspecified. Added in 11. Java documentation for java.nio.file.Path...
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › nio › file › Files.html
Files (Java SE 11 & JDK 11 )
January 20, 2026 - This method creates a new directory entry for the file so that it can be accessed using link as the path. On some file systems this is known as creating a "hard link". Whether the file attributes are maintained for the file or for each directory entry is file system specific and therefore not specified. Typically, a file system requires that all links (directory entries) for a file be on the same file system. Furthermore, on some platforms, the Java virtual machine may require to be started with implementation specific privileges to create hard links or to create links to directories.
🌐
Marco Behler
marcobehler.com › guides › java-files
How To Work With Files In Java
December 9, 2020 - // Java < 11 equivalent: Paths.get() path = Paths.get("c:/dev/licenses/windows/readme.txt"); System.out.println(path); Once you have a path object, you can finally do something with it. Let’s see what and how in the next section. When working with files or paths, you will likely be using the java.nio.file.Files class.
🌐
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.
🌐
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.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › io › File.html
File (Java SE 11 & JDK 11 )
January 20, 2026 - Instances of the File class are immutable; that is, once created, the abstract pathname represented by a File object will never change. The java.nio.file package defines interfaces and classes for the Java virtual machine to access files, file attributes, and file systems.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › nio › file › Path.html
Path (Java Platform SE 7 )
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.
🌐
OpenRewrite
docs.openrewrite.org › recipe catalog › java › modernize › nio › file › replace `paths.get` with `path.of`
Replace `Paths.get` with `Path.of` | OpenRewrite Docs
This recipe replaces all usages of `Paths.get` with `Path.of` for consistency. tags: - java11 preconditions: - org.openrewrite.Singleton recipeList: - org.openrewrite.java.ChangeMethodTargetToStatic: methodPattern: java.nio.file.Paths get(..) fullyQualifiedTargetTypeName: java.nio.file.Path - org.openrewrite.java.ChangeMethodName: methodPattern: java.nio.file.Path get(..) newMethodName: of · This recipe is used as part of the following composite recipes: ... This recipe has no required configuration options. It can be activated by adding a dependency on `org.openrewrite.recipe:rewrite-migrate-java` in your build file or by running a shell command (in which case no build changes are needed):
Published   1 month ago
🌐
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.