Reputation: 2102
I'm currently using eclipse for developing with Java. Could anyone explain the reason why files are put under the src directory when using classes like FileReader? and sometimes files have to be put under the bin directory when using methods like getClass().getResourceAsStream("...") for reading images? Are there any alternatives of the method getClass().getResourceAsStream("...") that require files under the src directory?
Upvotes: 0
Views: 62
Reputation: 17595
You as developer put nothing in the bin
directory, you only put stuff in src
and resources
directories, when the IDE - or any other build tool - builds your project then the generated class files and other resources are put to the bin directory.
Resources which are located in the bin
directory - and later bundled in your artifacts .jar
or .war
etc. - are available in your application's classpath
and can be accessed by class loaders, which enables classes to be loaded and enables you to find resources using getClass().gerResourceAsStream()
.
Upvotes: 6