java.io.file.sync_Java File toURI()方法

Java File toURI()方法

java.io.File.toURI() 方法创建一个文件:URI用来表示抽象路径名。

1 语法

public URI toURI()

2 参数

3 返回值

该方法返回一个绝对的,分层与计划等于“file”的URI。

4 示例

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

/**

* java.io.File.toURI()方法的例子

*/

import java.io.File;

import java.net.URI;

public class Demo {

public static void main(String[] args) {

File f = null;

URI uri;

boolean bool = false;

try {

// create new File object

f = new File("c:/java test.txt");

// returns true if file exists

bool = f.exists();

// if file exists

if(bool) {

// returns the uri string

uri = f.toURI();

// print

System.out.println("uri: "+uri);

}

} catch(Exception e) {

// if any error occurs

e.printStackTrace();

}

}

}

输出结果为:

uri: file:/c:/java%20test.txt


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部