java - 文件 : URIs and Slashes

标签 java windows uri file-uri

我正在开发的一个应用程序涉及访问网络文件共享上的文件,我们使用 URI 来指定文件的位置。

我对文件的理解:URI应该是file://+path的形式。在 Windows 网络共享的情况下,此路径类似于 \\servername\dir\file,因此生成的 URI 变为 file:////servername/dir/file.

这似乎对 Java 的 URI class 很有效,但 Win32 API 似乎需要一个 file://servername/dir/file 样式的 URI,Java 拒绝它,因为它“具有权限组件”。

我是否正确理解了网络共享 URI?有没有另一种方法可以指定路径而 Java 不会提示权限?

编辑:我们希望能够将路径存储为 URI,以便利用 URI 的方案部分来指定其他位置(例如文件:与其他:)。但正如所指出的,Java 似乎可能只是有自己的 URI 问题......

最佳答案

似乎Java is wrong :

Incorrect: file:////applib/products/a%2Db/abc%5F9/4148.920a/media/start.swf
Correct: file://applib/products/a-b/abc_9/4148.920a/media/start.swf

关于 UNC paths in Java :

The URI class handles UNC paths reasonably well, but has some problems. In the Java class libraries, the string representation of a UNC path is as follows:

new File("//SERVER/some/path").toURI().toString()
                                                -> "file:////SERVER/some/path

In other words, the URI stores the entire UNC path in the path component of the URI, and leaves the server/authority component empty. As long as you consistently use this string representation you will be able to interact successfully with java.net.URI.

关于java - 文件 : URIs and Slashes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1878024/

相关文章:

java - MySQL+Java webService+Android 客户端 : Is is better to make multiple queries or one big?

java - Spring MVC 父模板模型组件

c++ - Linux编译代码失败,Windows编译成功 : Cause/Fix?

windows - 如何检查网络共享EXE文件是否被多个用户使用?

android - 转换文件 : Uri to File in Android

java - 存储主机名和端口的最佳方式是什么?

使用数据路径的 Android Intent 过滤器

java - 在 JOOQ 的 ON DUPLICATE KEY 中返回 id

java - 我怎样才能实现java EOF

windows - Delphi 的 XP/2003 中的 SetFileInformationByHandle?