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

编程入门 行业动态 更新时间:2024-10-22 09:50:36
本文介绍了与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应该是什么样的?

本文发布于:2023-11-01 18:00:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550020.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:相对应   路径   应该是   文件   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!