所以我有2个文件在同一个文件夹。 “example.csv”和“example.jpg”,但是当我运行这段代码时,我得到example.jpg的路径,但是加载example.csv会抛出一个Nullpointer。加载CSV文件抛出NullPointerException
System.out.println(this.getClass().getResource("/example.csv").getFile());
System.out.println(this.getClass().getResource("/example.jpg").getFile());
THX对于任何帮助
堆栈跟踪的确切错误是什么?你有没有做过任何调试? – Carcigenicate
你确定前面的'/'是文件名吗? – SHG
重复的https://stackoverflow.com/questions/2593154/get-a-resource-using-getresource或https://stackoverflow.com/questions/2343187/loading-resources-using-getclass-getresource/41781868#41781868 – geneSummons