【问题标题】:How should a file: URI corresponding to a Windows path name look like?文件:对应于 Windows 路径名的 URI 应该是什么样子?
【发布时间】:2011-11-01 09:16:21
【问题描述】:

我正在尝试在代码中动态加载 MySQL jar,但我不确定 Windows 路径名的格式。我在下面使用的是正确的,用于从拇指驱动器加载 .jar 吗?

URL u = new URL("jar:file:G:/mysql-connector-java-5.1.15.jar!/");
URLClassLoader ucl = new URLClassLoader(new URL[] { u });

现在,这与您在 Java 教程中看到的传统路径不同:

URL url = new URL("file:/g:/mysql-connector-java-5.1.15.jar");

对于答案,我正在寻求澄清;我想我只是被“jar:file:”和“!”搞糊涂了。最后。

【问题讨论】:

  • Actually, file:///g:/... 用于本地系统上的文件。没有斜线,它是一个

标签: java file url jar


【解决方案1】:

File 对象上使用toURI() 方法应该可以解决问题:

final URL u = new File("g:/something.jar").toURI().toURL();
URLClassLoader ucl = new URLClassLoader(new URL[] { u });

【讨论】:

  • 稍后我会尝试 System.out.println(myfile.toURI()) 并让您知道会发生什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-09
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
  • 1970-01-01
  • 2014-04-10
相关资源
最近更新 更多