与Windows路径名相对应的文件:URI应该是什么样的? [英] How should a file: URI corresponding to a Windows path name look like?

查看:61
本文介绍了与Windows路径名相对应的文件:URI应该是什么样的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过代码动态加载MySQL jar,但是我不确定Windows路径名的格式.我下面使用的是正确的,用于从thumbdrive加载.jar吗?

I am trying to load a MySQL jar dynamically in code but I am unsure about the format of the Windows path name. Is what I am using below correct, for loading a .jar from a thumbdrive?

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

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

Now, this is not the same as the traditional path that you see in Java tutorials:

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

对于这个问题,我正在寻求澄清;我想我只是对"jar:file:"和!"感到困惑.最后.

For the answer, I am looking for clarification; I guess I am just confused by the "jar:file:" thing and also the "!" at the end.

推荐答案

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

Using toURI() method on the File object should do the trick:

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

这篇关于与Windows路径名相对应的文件:URI应该是什么样的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆