You can use the Path api:

Path p = Paths.get(yourFileNameUri);
Path folder = p.getParent();
Answer from assylias on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ file-getpath-method-in-java-with-examples
File getPath() method in Java with Examples - GeeksforGeeks
July 11, 2025 - ... // Java program to demonstrate the // use of getPath() function import java.io.*; public class solution { public static void main(String args[]) { // try catch block to handle exceptions try { // Create a file object File f = new ...
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ javas-paths-get-method-explained-9586c13f2c5c
Javaโ€™s Paths.get() Method Explained | Medium
September 8, 2024 - Explore how Java's Paths.get() method simplifies cross-platform file management by converting strings or URIs into file paths with ease.
๐ŸŒ
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:
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ nio โ€บ file โ€บ Path.html
Path (Java Platform SE 8 )
April 21, 2026 - In addition, the toFile method is useful to construct a File from the String representation of a Path. Implementations of this interface are immutable and safe for use by multiple concurrent threads. ... Returns the file system that created this object. ... Tells whether or not this path is ...
๐ŸŒ
Dev.java
dev.java โ€บ learn โ€บ java-io โ€บ file-system โ€บ file-path
Accessing Resources using Paths - Dev.java
January 25, 2023 - At the appropriate time, you can use the methods in the Files class to check the existence of the file corresponding to the Path, create the file, open it, delete it, change its permissions, and so on. Perhaps you have legacy code that uses java.io.File and would like to take advantage of the java.nio.file.Path functionality with minimal impact to your code.
๐ŸŒ
HappyCoders.eu
happycoders.eu โ€บ java โ€บ file-and-directory-names-file-path-paths
File and Directory Names in Java: File, Path, Paths
November 29, 2024 - Once we have the absolute directory path in a String (for example, from a configuration file), we can pass it directly to the File constructor. The following example uses a String constant for simplicity: File directory = new File("/var/log...
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-file-path-absolute-canonical
Java File Path, Absolute Path and Canonical Path | DigitalOcean
August 3, 2022 - I need to pass the full path and file name for the selected files to apache pdf box class to get the excel extracts. /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.pdfet.pdfext; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.event.ActionListener; //import com.pdfet.pdfext.ExtensionFileFilter; import java.io.File; import javax.swing.filechooser.FileFilter; /** * * @author vak_salem */ class ExtensionFileFilter extend
Find elsewhere
๐ŸŒ
Marc Nuri
blog.marcnuri.com โ€บ home โ€บ how to convert file to path and path to file in java
How to convert File to Path and Path to File in Java - Marc Nuri
August 22, 2023 - As Java programmers we will often need to convert from one to the other. The following sections show you how. The File class has a method toPath() that returns a Path object representing the path of the file.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java io โ€บ list files in a directory in java
List Files in a Directory in Java | Baeldung
January 8, 2024 - Java 8 introduced a new list() method in java.nio.file.Files. The list method returns a lazily populated Stream of entries in the directory. ... public Set<String> listFilesUsingFilesList(String dir) throws IOException { try (Stream<Path> stream = Files.list(Paths.get(dir))) { return stream .filter(file -> !Files.isDirectory(file)) .map(Path::getFileName) .map(Path::toString) .collect(Collectors.toSet()); } }
๐ŸŒ
Docker Hub
hub.docker.com โ€บ _ โ€บ eclipse-temurin
eclipse-temurin - Official Image | Docker Hub
To run a pre-built jar file with the latest OpenJDK 25, use the following Dockerfile: FROM eclipse-temurin:25 RUN mkdir /opt/app COPY japp.jar /opt/app CMD ["java", "-jar", "/opt/app/japp.jar"] Copy
๐ŸŒ
Render
render.com
Render | The cloud for builders
Store and retrieve files from your services with lightweight SDKs.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_files.asp
Java Files
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... File handling is an important part of any application.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_getstarted.asp
Java Getting Started
In Java, every application begins with a class name, and that class must match the filename.
๐ŸŒ
Visual Studio Code
code.visualstudio.com โ€บ docs โ€บ java โ€บ java-tutorial
Getting Started with Java in VS Code
November 3, 2021 - If you have never installed a JDK before and need to install one, we recommend you to choose from one of these sources: ... Create a folder for your Java program and open the folder with VS Code. Then in VS Code, create a new file and save it with the name Hello.java.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-extract-file-extension-from-a-file-path-string-in-java
How to Extract File Extension From a File Path String in Java? - GeeksforGeeks
July 23, 2025 - Otherwise, it extracts the substring from the index after the last dot to the end of the file path, effectively giving the file extension. Example file paths are provided to showcase the method in action. The results are printed, demonstrating how the method accurately extracts file extensions. Handles cases where no extension is present, returning an appropriate message. ... import java.io.File; // Driver Class public class Code2 { // Main Function public static void main(String[] args) { String filepath = "example.txt"; // It will print file name and extension printFileNameAndExtension(filep
๐ŸŒ
Apache Kafka
kafka.apache.org โ€บ documentation
Documentation Redirect | Apache Kafka
May 22, 2026 - Redirecting ยท Security | Donate | Thanks | Events | License | Privacy
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ java โ€“ read a file from resources folder
Java - Read a file from resources folder - Mkyong.com
September 4, 2020 - In Java, we can use getResourceAsStream or getResource to read a file or multiple files from a resources folder or root of the classpath.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ i/o โ€บ reading a file from classpath in java
Reading a File from Classpath in Java
April 11, 2022 - To read any file from the classpath in a class, we have to get the reference of the system classloader for that class that is trying to read the file. System classloader obviously knows the other paths for the application.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java io โ€บ getting the filename from a string containing an absolute file path
Getting the Filename From a String Containing an Absolute File Path | Baeldung
January 8, 2024 - Once we have a Path object, we can get the filename by calling the Path.getFileName() method. Unlike the File class, we can create a Path instance using the static Paths.get() method.