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 › 17 › docs › api › java.base › java › nio › file › Path.html
Path (Java SE 17 & JDK 17)
April 21, 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 › 17 › docs › api › java.base › java › nio › file › Paths.html
Paths (Java SE 17 & JDK 17)
April 21, 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 › 17 › docs › api › java.base › java › nio › file › class-use › Path.html
Uses of Interface java.nio.file.Path (Java SE 17 & JDK 17)
January 20, 2026 - Returns a BodyHandler<Path> that returns a BodySubscriber<Path> where the download directory is specified, but the filename is obtained from the Content-Disposition response header. Methods in java.nio.channels with parameters of type Path
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.

🌐
Intrexx
help.intrexx.com › apidocs › jdk17 › api › java.base › java › nio › file › package-summary.html
java.nio.file (Java SE 17 & JDK 17)
An object that may be used to locate a file in a file system. ... An interface that is implemented by objects that perform match operations on paths.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › nio › file › FileSystem.html
FileSystem (Java SE 17 & JDK 17)
April 21, 2026 - Leading period/dot characters in file name are treated as regular characters in match operations. For example, the "*" glob pattern matches file name ".login". The Files.isHidden(java.nio.file.Path) method may be used to test whether a file is considered hidden.
🌐
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
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › nio › file › FileVisitOption.html
FileVisitOption (Java SE 17 & JDK 17)
October 20, 2025 - Files.walkFileTree(java.nio.file.Path, java.util.Set<java.nio.file.FileVisitOption>, int, java.nio.file.FileVisitor<? super java.nio.file.Path>) Enum.EnumDesc<E extends Enum<E>> Enum Constants · Enum Constant · Description · FOLLOW_LINKS · Follow symbolic links.
🌐
Intrexx
help.intrexx.com › apidocs › jdk17 › api › java.base › java › nio › file › class-use › Path.html
Secure Login
A modern browser is required to view this site. Please use the latest version of Chrome, Firefox, Safari, or Edge · JavaScript is required to login. Please enable JavaScript and reload the page
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › io › File.html
File (Java SE 17 & JDK 17)
April 21, 2026 - Marks the file or directory named by this abstract pathname so that only read operations are allowed. ... A convenience method to set the owner's write permission for this abstract pathname. ... Sets the owner's or everybody's write permission for this abstract pathname. ... Returns a java.nio.file.Path object constructed from this abstract path.
🌐
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 › 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.
🌐
javaspring
javaspring.net › blog › java-nio-file-path
Mastering Java NIO File Path: A Comprehensive Guide — javaspring.net
Java NIO file paths provide a powerful and flexible way to work with files and directories in the file system. By understanding the fundamental concepts, usage methods, common practices, and best practices, you can write more efficient and robust ...
🌐
Jenkov
jenkov.com › tutorials › java-nio › path.html
Java NIO Path
Do not confuse a file system path with the path environment variable in some operating systems. The java.nio.file.Path interface has nothing to do with the path environment variable.
🌐
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.
🌐
Java
download.java.net › java › early_access › panama › docs › api › java.base › java › nio › file › Path.html
Path (Java SE 19 & JDK 19 [build 1])
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.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-files-nio-files-class
Java Files - java.nio.file.Files Class | DigitalOcean
August 4, 2022 - Files class provides createFile(Path filePath, FileAttribute<?>… attrs) method to create file using specified Path. Let’s have a look at the below example program. package com.journaldev.examples; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; /** * Java Create file using Files class * * @author pankaj * */ public class FilesCreateFileExample { public static void main(String[] args) { //initialize Path object Path path = Paths.get("D:/data/file.txt"); //create file try { Path createdFilePath = Files.createFile(path); System.out.println("File Created at Path : "+createdFilePath); } catch (IOException e) { e.printStackTrace(); } } }