我收到一个非常恼人的错误,代码很好,但无法找到文件。
Output:
.\res\shadersbasicVertex.vs (The system cannot find the file specified) <-- yes it does actually say '\shadersbasicVertex.vs'
继承我加载资源的地方(或指定路径的地方)
shaderReader = new BufferedReader(new FileReader("./res/shaders" + fileName));
库使用:lwjgl
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at com.base.engine.ResourceLoader.loadShader(ResourceLoader.java:15)
at com.base.engine.Game.<init>(Game.java:20)
at com.base.engine.MainComponent.<init>(MainComponent.java:20)
at com.base.engine.MainComponent.main(MainComponent.java:124)
我的着色器文件夹位于: C:\ Users \ Badfitz66 \ workspace \ Rain \ Game engine \ res \ shaders
答案 0 :(得分:3)
是的,大概fileName
是"basicVertex.vs"
。将其放在"./res/shaders"
的末尾,您将获得.\res\shadersbasicVertex.vs
。你需要一个额外的斜线:
shaderReader = new BufferedReader(new FileReader("./res/shaders/" + fileName));
或者您可以使用File
API来解析路径:
File file = new File(new File("res", "shaders"), fileName);
shaderReader = new BufferedReader(new FileReader(file));
或者更好:
shaderReader = Files.newBufferedReader(Paths.get("res", "shaders", fileName));
请注意:
FileReader
始终使用平台默认编码;我建议使用一种允许您指定编码的方法 - 最后一个示例,但默认为UTF-8。