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 › 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 – 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 ...
Discussions

windows - String of java.nio.file.Path - Stack Overflow
Can someone explain what I'm doing wrong and/or missing here. I have java.nio.file.Path objects that work fine in my Java application. The only issue is when I try to print them out in logs, and the More on stackoverflow.com
🌐 stackoverflow.com
Get java.nio.file.Path object from java.io.File - Stack Overflow
Returns a File object representing this path. ... Returns a java.nio.file.Path object constructed from the this abstract path. More on stackoverflow.com
🌐 stackoverflow.com
file - How to get the path string from a java.nio.Path? - Stack Overflow
However, you get strange results: Paths.get("/tmp", "foo").toString() returns /tmp/foo here. What is your filesystem? ... Sign up to request clarification or add additional context in comments. ... Updated question with more info on when this fails. 2013-07-09T16:33:12.87Z+00:00 ... Yes, I'm sure :) java.nio... More on stackoverflow.com
🌐 stackoverflow.com
Java nio: How to add extension to an absolute path? - Stack Overflow
This feels like it should be something straight forward, but I can seem to find an elegant solution to it without converting to File. Given a Path Path path = Paths.get("/a/b/foo") How to do get ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
Medium
medium.com › @AlexanderObregon › javas-paths-get-method-explained-9586c13f2c5c
Java’s Paths.get() Method Explained | Medium
September 8, 2024 - Java’s Paths.get() method from the java.nio.file.Paths class is a fundamental tool for handling file paths. It allows us to create Path objects, which can be used to represent file and directory paths in a platform-independent manner.
🌐
TutorialsPoint
tutorialspoint.com › java_nio › java_nio_path.htm
Java NIO - Path
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.As path interface is in Java NIO package so it get its qualified ...
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Paths.html
Paths (Java Platform SE 8 )
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. Since: 1.7 · clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait ·
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 - In this article, we showed Path operations in the new file system API (NIO2) that was shipped as a part of Java 7 and saw most of them in action.
🌐
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.
🌐
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 will be appended to the sequence after "first" separated by "/". ... // Java program to demonstrate // java.nio.file.Path.get(String first,String...
🌐
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.
🌐
Kimballcontractorsllc
kimballcontractorsllc.com › 4SVU
AntiBot Cloud: скрипт для защиты сайтов на php от плохих ботов.
February 20, 2026 - This process is automatic. Your browser will redirect to your requested content shortly · Please allow up to 1 seconds
🌐
TutorialsPoint
tutorialspoint.com › home › practice › all problems
Coding Practice Problems & Tutorials | TutorialsPoint
Practice 3500+ coding problems and tutorials. Master programming challenges with problems sorted by difficulty. Free coding practice with solutions.
🌐
Oracle
docs.oracle.com › en › java › javase › 25 › docs › api › java.base › java › nio › file › class-use › Path.html
Uses of Interface java.nio.file.Path (Java SE 25 & JDK 25)
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
🌐
GitHub
github.com › minio › minio
GitHub - minio/minio: MinIO is a high-performance, S3 compatible object store, open sourced under GNU AGPLv3 license. · GitHub
April 25, 2026 - Start MinIO by running minio server PATH where PATH is any empty folder on your local filesystem.
Starred by 61.3K users
Forked by 7.7K users
Languages   Go
🌐
Reddit
reddit.com › r/learnprogramming › java file io absolute paths and directories question
r/learnprogramming on Reddit: Java File IO Absolute Paths and Directories Question
June 28, 2021 -

Good afternoon, I am currently implementing the native Java File IO functionality within my project in order to write XML data-structures to the disc. This will be used for saving GUI configurations for my portfolio project (A raycasting based game engine)

Everything is working correctly BUT Java defaults to a local absolute-path if the directory of a file is not specified in the handle String. This is what I want, as the engine needs to dynamically store user data in a non-hardcoded directory (obviously) But the default absolute-path is just the root folder of the project; which is not ideal as it is too exposed, will clutter the project folder, and doesn't sit well with my OCD.

How can I find a way around this and have java create the files within a specific resources folder, while not hard-coding this as a directory?