JAVA third method to read the configuration file is:
The first reading of XML
The second reading of INI
Now consider reading this document
package temp;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Test (
public static void main (String [] args) (
String config = "dbconfig.properties"; / / specify the configuration file to read
Properties prop = new Properties ();
InputStream is;
try (
is = new FileInputStream (config);
prop.load (is);
) Catch (FileNotFoundException e) (
System.out.println ("can not find the specified configuration file.");
e.printStackTrace ();
) Catch (IOException e) (
e.printStackTrace ();
)
/ / Here is the specific information read the configuration file
String driver = prop.getProperty ("driver");
System.out.print (driver);
)
)
Properties of our file on this: F: \ Symposium \ java and the configuration file summary \ ConfigSecond directory.
没有评论:
发表评论