一、读取properties文件:

properties中的内容:

server.ip = 127.0.0.1
server.port = 22
//原生java即可读取
public
static void setting() throws FileNotFoundException, IOException{ File configFile = new File("conf/parameters.properties"); FileInputStream fis = new FileInputStream(new File(configFile .getAbsoluteFile().getCanonicalPath())); Properties props = new Properties(); props.load(fis); String serverIp = (String) props.get("server.ip"); InetAddress inetAddress = InetAddress.getByName(serverIp); Integer serverPort = Integer.valueOf((String) props.get("server.port")); }

二、读取ini文件:

ini文件中的内容:

[server]
ip=127.0.0.1
port=22

需要引入ini4j的jar包,包下载地址:https://repo1.maven.org/maven2/org/ini4j/ini4j/0.5.4/ini4j-0.5.4.jar

Wini ini = new Wini(new File("conf/monitor.ini"));
       String serverIp = ini.get("server","ip");
       InetAddress inetAddress = InetAddress.getByName(serverIp);
       Integer serverPort = Integer.valueOf(ini.get("server","port"));
02-10 13:46