从属性文件读取密钥时出现问题 java

Problems reading keys from properties file java

我有一个属性文件,用于控制我的应用程序中的特定变量。由于应用程序一直在运行,我使用的所有键都可以正常工作。

ini文件的结构是:

JDBC_DRIVER=com.mysql.jdbc.Driver
DB_URL=localhost/tempTables
EmailList=foo@bar.com
sender=foo_bar@tempfoo.com
host=<sanitised>
port=25
USER=root
PASS=Fo0b4R
path=C:/Users/foo/Desktop/profile_admin_
logLevel=2
TimerControl=2

我遇到问题的具体密钥是 "logLevel"。这将作为字符串读取(使用属性 Class),然后解析为 int。键 "port" 很好地遵循了这一套所以我想知道它是否是键名,或者键的数量是否有限制。

各键读法如下:

FileInputStream propFile = new FileInputStream("config.ini");
Properties config = new Properties(System.getProperties());
config.load(propFile);
String level = config.getProperty("logLevel");
System.out.println("Purely for testing. Key \"logLevel\" is :"+level);
int levelLogger = Integer.parseInt(level);
System.out.println("Parsed to integer, printed for integrity: "+levelLogger);
//output
Purely for testing. Key "logLevel" is : null
Exception in thread "main"
java.lang.NumberFormatException: nu;;
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at package.myClass.main(myClass.java:63)

这里的问题是我自己的错。因为我正在为我的 ini 使用当前工作目录,所以我忘记将 config.ini 移动到 /bin 文件夹(我正在从 CMD 执行此应用程序。