getResource使用java 1.7 windows 7在磁盘名称前面/前面 [英] getResource puts a leading / before the disk name using java 1.7 windows 7

查看:164
本文介绍了getResource使用java 1.7 windows 7在磁盘名称前面/前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是磁盘名称前面的前导斜杠。
如何避免这种情况?

The following gives a leading slash before the disk name. How can I avoid that?

String pngpath = getClass().getResource("/resources/lena.png").getPath();
System.out.println("pngpath = "+pngpath);

给予:

pngpath = /C:/Users/jgrimsdale/Documents/NetBeansProjects/HelloCV/build/classes/resources/lena.png


推荐答案

使用:

String pngpath = getClass().getResource("/resources/lena.png").getFile();
File file = new File(pngpath);
System.out.println(file.getAbsolutePath());

这篇关于getResource使用java 1.7 windows 7在磁盘名称前面/前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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