Arvind
Arvind

Reputation: 6474

java beginner- in which folder should I place a "database.properties" file

I read some tutorials on how to read data from a database.properties file- which basically stored key-value pairs.

What i want to know is, in which folder should I place this file? Is it in the root (ie "src") or within a package... And how do I access this file, if it is placed in "src"- my code will be within a package (and the package's directory will be under src)- so how do I access the properties file, which is in "src", from a class within a package?

Upvotes: 0

Views: 497

Answers (3)

BlackVegetable
BlackVegetable

Reputation: 13034

Where to place your file is a subjective matter (of which I am no expert.) However, you should remember that your classpath begins with your project folder implicitly. Also, you can access your packages the same way as you access a folder on your OS.

So a file in your src package named foo.txt would be : loadingMethod("src/foo.txt")

Upvotes: 0

Priyank Doshi
Priyank Doshi

Reputation: 13151

Best approach is under src/main/resources.

Upvotes: 0

Akhi
Akhi

Reputation: 2242

Ideally it should be in the external folder(src/main/resources) not along with the .java. Use ResourceBundle for reading it.

Upvotes: 3

Related Questions