gpt4 book ai didi

java - getpath 函数的路径无效

转载 作者:太空宇宙 更新时间:2023-11-04 13:08:47 26 4
gpt4 key购买 nike

在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

路径中没有任何名为 %5c 的内容。您能告诉我为什么会出现这种情况或者如何避免这种情况吗?

最佳答案

对于 getResource,您需要使用常用的斜杠而不是反斜杠:

getResource("Emoticons/happy.PNG")

关于java - getpath 函数的路径无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34169893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com