The following gives a leading slash before the disk name. How can I avoid that?
String pngpath = getClass().getResource("/resources/image.png").getPath();
System.out.println("pngpath = "+pngpath);
Gives:
pngpath = /C:/Users/jgrimsdale/Documents/NetBeansProjects/HelloCV/build/classes/resources/image.png
Use:
String pngpath = getClass().getResource("/resources/image.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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With