getpath 函数的无效路径
Invalid path by getpath Function
在 java 中,我必须获取图像的确切位置,该图像位于包内源目录下的文件夹(表情符号)中,但每当我调用
String s= (Main.class.getResource("Emoticons\happy.PNG")).getPath();
System.out.println(s);
emotable.put(emo[0], s);
它给了我一个像这样的无效路径
/E:/oop/java/emoti/out/production/emoti/sample/Emoticons%5chappy.PNG
path.Can 中没有叫 %5c 的东西,你告诉我它为什么会出现或如何避免它。
对于 getResource,您需要使用的不是反斜杠,而是常用的斜杠:
getResource("Emoticons/happy.PNG")
在 java 中,我必须获取图像的确切位置,该图像位于包内源目录下的文件夹(表情符号)中,但每当我调用
String s= (Main.class.getResource("Emoticons\happy.PNG")).getPath();
System.out.println(s);
emotable.put(emo[0], s);
它给了我一个像这样的无效路径
/E:/oop/java/emoti/out/production/emoti/sample/Emoticons%5chappy.PNG
path.Can 中没有叫 %5c 的东西,你告诉我它为什么会出现或如何避免它。
对于 getResource,您需要使用的不是反斜杠,而是常用的斜杠:
getResource("Emoticons/happy.PNG")