java uri 文件
文件类URI toURI() (File Class URI toURI())
This method is available in package java.io.File.toURI().
软件包java.io.File.toURI()中提供了此方法。
URI stands for Uniform Resource Identifier.
URI代表统一资源标识符。
This method creates a file URI (i.e. URI is nothing but it is a filepath).
此方法创建一个文件URI(即URI什么都不是,但它是一个文件路径)。
This method will throw a security exception if we access an unauthorized property.
如果我们访问未授权的属性,则此方法将引发安全异常。
This method is accessible with file object.
该方法可通过文件对象访问。
Syntax:
句法:
URI toURI(){
}
Parameter(s):
参数:
We don't pass any object as a parameter in the method of the File.
我们不会在File方法中将任何对象作为参数传递。
Return value:
返回值:
The return type of this method is URI, it returns absolute filepath of the file if exists.
此方法的返回类型为URI ,如果存在,则返回文件的绝对文件路径。
Java程序演示toURI()方法的示例 (Java program to demonstrate example of toURI() method)
// import the File class because we will use File class methods
import java.io.File;
// import the Exception class because it may raise an exception
// when working with files
import java.lang.Exception;
// For accessing net files
import java.net.URI;
public class URIClass {
public static void main(String[] args) {
try {
// Specify the path of file and we use double slashes to
// escape '\' character sequence for windows otherwise
// it will be considerable as url.
URI uni_res_iden;
File file = new File("E:\\Programs\\myjava.txt");
if (file.exists()) {
uni_res_iden = file.toURI();
System.out.println("The URI of the file is : " + " " + uni_res_iden);
}
} catch (Exception e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
Output
输出量
E:\Programs>javac URIClass.java
E:\Programs>java URIClass
The URI of the file is : file:/E:/Programs/myjava.txt
翻译自: https://www.includehelp.com/java/file-class-uri-touri-method-with-example.aspx
java uri 文件