本地资源的 URI

发布于 2024-08-25 17:34:26 字数 53 浏览 2 评论 0原文

在 Java 中,我可以为位于硬盘本地的文件创建 URI 吗?如果可以的话,应该如何构建呢?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故人如初 2024-09-01 17:34:26

查看文件文档

文件有一个构造函数,它以 URI 作为参数,如果你想从现有文件中获取 URI,它还有方法 toURI() 。您可以尝试一下以了解应该如何完成这些事情。

您还可以阅读URI(它不是一个java术语)。维基百科上有一个例子:

文件:///home/用户名/RomeoAndJuliet.pdf

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

爱的十字路口 2024-09-01 17:34:26
URI uri = new URI("file:///filename.txt");

如果您使用的是 Windows:

URI uri = new URI("file:///C:/fun/filename.txt");
URI uri = new URI("file:///filename.txt");

If you're using Windows:

URI uri = new URI("file:///C:/fun/filename.txt");
静水深流 2024-09-01 17:34:26

尝试以下:

URI uri = new URI("file:///C:/other/mydir/myfile.txt");

Try below:

URI uri = new URI("file:///C:/other/mydir/myfile.txt");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文