字符串的外部文件,而不是硬编码 [英] External file for strings, as opposed to hardcoding them

查看:144
本文介绍了字符串的外部文件,而不是硬编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有开发一些Android应用程序的经验,它们可以容易地存储可以存储字符串的XML字符串文件。最后一次我开发了一个桌面Java应用程序,我硬编码字符串(例如按钮标题,标签等)。我已经知道这是不好的做法,我应该将字符串存储在一个文件中。



我不知道该怎么做这个。




  • 我目前正在Eclipse中开发。我应该在文件夹中粘贴文本文件吗?

  • 这是标准吗?

  • 如何在代码中找到该文件?


解决方案

是的,你应该使用 .properties 文件,并使用 ResourceBundle


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?

解决方案

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

这篇关于字符串的外部文件,而不是硬编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆