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);
Gives:
pngpath = /C:/Users/jgrimsdale/Documents/NetBeansProjects/HelloCV/build/classes/resources/lena.png
Use:
String pngpath = getClass().getResource("/resources/lena.png").getFile();
File file = new File(pngpath);
System.out.println(file.getAbsolutePath());
A constructor of File(uri) or File(string) helps to get file object from system dependent path string or URI object.
It is a solution to using the Java Library.
System.out.println(new File("/C:/Users/jgrimsdale").toString())
https://docs.oracle.com/javase/7/docs/api/java/io/File.html#File(java.net.URI)
you can do this using this code.
System.out.println("pngpath = "+pngpath.substring(1,pngpath.length()));