URI for local resources

2020-03-09 09:07发布

In Java can I create a URI for a file located locally in the hard drive? If so, how should it be constructed?

标签: java uri
3条回答
姐就是有狂的资本
2楼-- · 2020-03-09 09:28

Try below:

URI uri = new URI("file:///C:/other/mydir/myfile.txt");
查看更多
疯言疯语
3楼-- · 2020-03-09 09:34

Look at File documentation:

File has a constructor, which takes URI as a parameter, and it also has method toURI() if you want to get URI from existing file. You can play with that to understand how the things should be done.

You can also read about URI (it's not a java term). There is an example in Wikipedia:

file:///home/username/RomeoAndJuliet.pdf

查看更多
神经病院院长
4楼-- · 2020-03-09 09:47
URI uri = new URI("file:///filename.txt");

If you're using Windows:

URI uri = new URI("file:///C:/fun/filename.txt");
查看更多
登录 后发表回答