- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get file URI reference in Java?
The class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.
In general, an URI (Uniform Resource Identifier) represents a resource. The URI class of Java represents this format You can get the URI format of a file by invoking the toURI() method.
Example
Following Java example, prints the URI format of the file named samplefile.txt
import java.io.File; import java.io.IOException; import java.net.URI; public class GetURI { public static void main(String args[]) throws IOException { //Instantiating the File class String filePath = "D:\ExampleDirectory\sampleFile.txt"; File file = new File(filePath); //Getting the URI object URI uri = file.toURI(); System.out.println(uri.toString()); } }
Output
file:/D:/ExampleDirectory/sampleFile.txt
- Related Articles
- How to Get File Owner’s Name in Java?
- How to get file last modified time in Java?
- Get file extension name in Java
- How to reference embedded Docker resource files using file path URL?
- How to get or reference cell from another worksheet in Excel?
- How to declare reference types in JShell in Java 9?
- Get Absolute path of a file in Java
- How do I get a reference to the app delegate in Swift?
- How to get the file name from the file path in Python?
- Differences between Method Reference and Constructor Reference in Java?
- How to get Exception log from a console and write it to external file in java?
- How to implement my own URI scheme on Android?
- When can a .class file get created in Java?
- How to implement DoubleSupplier using lambda and method reference in Java?
- How to create a constructor reference for an array in Java?

Advertisements