如何用Java读取配置文件 [英] How to read a configuration file in Java
问题描述
我正在做一个构建线程池化服务器
的项目,其中我必须设置
I am doing a project to build thread pooled web server
, in which I have to set
- 服务器侦听的端口号。
- 线程池中有多少个线程
- 根目录的绝对路径,以及许多要点。
一种方法是在代码中硬编码所有这些变量,我做了。但是从专业角度来说它并不好。
One way is to hard code all these variables in the code, that I did. But professionally it is not good.
现在,我想制作一个配置文件,我将所有这些数据放入其中,并在运行时我的代码获取这些数据。
Now, I want to make one configuration file, in which I put all these data, and at the run time my code fetches these.
如何为上述任务制作配置文件?
How can I make configuration file for the above task ?
推荐答案
这取决于。
从基本I /开始O ,请查看属性,查看首选项API ,甚至可能用于XML处理的Java API 和用于XML绑定的Java体系结构
Start with Basic I/O, take a look at Properties, take a look at Preferences API and maybe even Java API for XML Processing and Java Architecture for XML Binding
如果这些都不能满足您的特定需求,那么甚至可以看一下使用某种数据库
And if none of those meet your particular needs, you could even look at using some kind of Database
这篇关于如何用Java读取配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!