Java:读取.ini文件

利用java.util.Properties可以非常方便的读取ini配置文件。这里给一个简单例子。
首先,需要一个ini配置文件

;;myconfig.ini
para1=anels
para2=ruilinliu.com
;“\”是不能解析的,路径中可以用“/”代替“\”
path=c:/anels/test/


然后是程序:
import java.io.FileInputStream;
import java.util.Properties;

public class IniReader {

public static void main(String args[]) {
Properties ppt = new Properties();
try {
ppt.load(new FileInputStream(“myconfig.ini”));
} catch (Exception e) {}

//get properties
String p1 = ppt.getProperty(“para1”);
String p2 = ppt.getProperty(“para2”);
String pa = ppt.getProperty(“path”);

System.out.println(“p1: “+p1);
System.out.println(“p2: “+p2);
System.out.println(“pa: “+pa);
}
}

原创文章,转载请注明: 转载自 iDEAnels

本文地址: Java:读取.ini文件

One thought on “Java:读取.ini文件”

Leave a Reply

Your email address will not be published. Required fields are marked *