getResource puts a leading / before the disk name using 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); Gives: pngpath = /C:/Users/jgrimsdale/Documents/NetBeansProjects/HelloCV/build/classes/resources/lena.png 回答1: Use: String pngpath = getClass().getResource("/resources/lena.png").getFile(); File file = new File(pngpath); System.out.println(file.getAbsolutePath()); 回答2: A constructor of File(uri) or