版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/pengshengli/article/details/85062197
IniFile iniFile=new BasicIniFile();
File f = new File("");
String cf = null;
cf = f.getCanonicalPath();
File file=new File(cf+"\\config.ini");
IniFileReader rad=new IniFileReader(iniFile, file);
//IniFileWriter wir=new IniFileWriter(iniFile, file);
try {
//读取item
rad.read();
IniSection iniSection=iniFile.getSection(0);
IniItem iniItem=iniSection.getItem("IP");
ip=iniItem.getValue();
iniItem = iniSection.getItem("Database");
database=iniItem.getValue();
iniItem = iniSection.getItem("UID");
usr=iniItem.getValue();
iniItem = iniSection.getItem("PWD");
passwd=iniItem.getValue();
} catch (IOException e) {}
注意:ini文件内有中文,read()方法会报错