In the Java project, some configuration parameters are saved in the property file, so that the original code is not modified to directly modify the property file.
Propertyparser.java
Package Com.discover.parse;import Java.io.file;import Java.io.fileinputstream;import java.io.inputstream;import java.util.properties;/** * @author Administrator * */public class Propertyparser { /** * @param args */ public static void Main (string[] args) { //TODO auto-generated Method Stub Properties Properties = new properties (); String name = PropertyParser.class.getResource (""). GetPath (); String Path = name + "Config.properties"; File File = new file (path); if (file.exists ()) { try{ inputstream fis = new FileInputStream (file); Properties.load (FIS); System.out.println (properties.getproperty ("IP")); Fis.close (); } catch (Exception e) { //Todo:handle Exception } } }
Config.properties
[plain] view plain copy
- ip=127.0.0.1
Run the program, the console prints the results
Java parsing the property file (and the SQL execution time limit is written in XML, adding extensions, without changing the source code).