简体   繁体   English

与Windows路径名相对应的文件:URI应该是什么样的?

[英]How should a file: URI corresponding to a Windows path name look like?

I am trying to load a MySQL jar dynamically in code but I am unsure about the format of the Windows path name. 我正在尝试在代码中动态加载MySQL jar,但是我不确定Windows路径名的格式。 Is what I am using below correct, for loading a .jar from a thumbdrive? 我下面使用的是正确的,用于从thumbdrive加载.jar吗?

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

Now, this is not the same as the traditional path that you see in Java tutorials: 现在,这与您在Java教程中看到的传统路径不同:

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

For the answer, I am looking for clarification; 对于答案,我正在寻求澄清。 I guess I am just confused by the "jar:file:" thing and also the "!" 我想我对“ jar:file:”和“!”感到困惑。 at the end. 在末尾。

Using toURI() method on the File object should do the trick: File对象上使用toURI()方法应该可以解决问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM