Search code examples
javaeclipsefilehard-coding

External file for strings, as opposed to hardcoding them


I have experience developing some Android apps, which handily have XML string files where you can store strings. The last time I developed a desktop Java app I hard-coded the strings (for example button titles, labels etc...). I have since learned this is bad practice, and I should store strings in a file.

I am not sure how to go about doing this.

  • I am currently developing in Eclipse. Should I just stick a text file in my project folder?
  • Is this standard?
  • How do you locate the file in the code?

Solution

  • Yes, you should use .properties files and access them using ResourceBundle.