How to Get File URI Reference in Java


In this example we will show how to get a URI reference of a file object using the toURI() method.

Source Code

java
package com.beginner.examples;

import java.io.File;

public class getURITest {
	
	public static void main(String[] args) {
		
		//Create File object
		File file = new File("c:test.txt");
		
		//Use the toURI() method in the File object
		System.out.println(file.toURI());
		
		
	}

}

Ouput:

java
file:/c:/test.txt

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments