java读取windows下常用的配置文件ini格式,
这里使用的是一个开源的工具包org.dtools.javaini-v1.1.00
下载地址:http://javaini.sourceforge.net/download.html
举个例子
ini文件内容
aa.ini
#国家 [Country] China = 中国 Hong Kong = 香港 #语言 [language] Chinese = 汉语
读取代码
public void readIniFile() throws IOException{ IniFile iniFile = new BasicIniFile(); IniFileReader reader = new IniFileReader(iniFile, new File("e:/aa.ini")); reader.read(); for(int i=0;i<iniFile.getNumberOfSections();i++){ IniSection sec = iniFile.getSection(i); System.out.println("---- " + sec.getName() + " ----"); for(IniItem item : sec.getItems()){ System.out.println(item.getName() + " = " + item.getValue()); } } }
输出结果
---- Country ---- China = 中国 Hong Kong = 香港 ---- language ---- Chinese = 汉语