Badfitz66
Badfitz66

Reputation: 386

Could not find the file specified?

I get a really annoying error, code is fine but it can't find the files.

Output:
.\res\shadersbasicVertex.vs (The system cannot find the file specified) <-- yes it does actually say '\shadersbasicVertex.vs'

heres where I load the resources (or where I specify the path)

    shaderReader = new BufferedReader(new FileReader("./res/shaders" + fileName));

libraries im using: 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)

my shader folders are located at: C:\Users\Badfitz66\workspace\Rain\Game engine\res\shaders

Upvotes: 0

Views: 130

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503689

Well yes, presumably fileName is "basicVertex.vs". Put that on the end of "./res/shaders" and you'll get .\res\shadersbasicVertex.vs. You need an extra slash:

shaderReader = new BufferedReader(new FileReader("./res/shaders/" + fileName));

Or you could use the File API to resolve the path:

File file = new File(new File("res", "shaders"), fileName);
shaderReader = new BufferedReader(new FileReader(file));

Or better yet:

shaderReader = Files.newBufferedReader(Paths.get("res", "shaders", fileName));

Note that:

  • This has nothing to do with OpenGL or anything 3d - you're just opening a file
  • FileReader always uses the platform default encoding; I would recommend using an approach which allows you to specify the encoding - the last example does, but defaults to UTF-8.

Upvotes: 3

Related Questions