在web工程中,读取配置文件:其中config.ini放到工程的src目录下
读取配置文件类如下:
读取配置文件类如下:
package com.yuanhua;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ReadIni {
public static String rootPath;
public static String read()
{
Properties p = new Properties();
InputStream fis = null;
fis = ReadIni.class.getClassLoader().getResourceAsStream("config.ini");
try {
p.load(fis);
} catch (IOException e) {
e.printStackTrace();
}
rootPath = p.getProperty("path");
System.out.println(rootPath);
return rootPath;
}
public static void main(String[] args) {
read();
}
}