Properties are two ways to read the configuration file

The first is obtained by the method of absolute Road King through FileInputStream.
getProperties the Properties static public () {
the InputStream inputStream;
the Properties Properties = null;
the try {
inputStream new new = the FileInputStream ( "D: \\ \\ Workspace Commons-IO_Test the src \\ \\ \\ main mysqlNamePassword.properties Resources \\");
= the Properties new new Properties ();
Properties.load (inputStream);

} the catch (IOException E) {
e.printStackTrace ();
}
the finally {
return Properties;
}
}

The second is by JDBCText.class.getClassLoader () getResourceAsStream ( "mysqlNamePassword.properties").;

I created a class JDBCText

getClassLoader () is a class loader


getResourceAsStream is to obtain resources inside and resources in the form of streams

getProperties the Properties static public () {
the Properties Properties new new = the Properties ();
the InputStream inStream = null;
the try {
inStream = JDBCText.class.getClassLoader () the getResourceAsStream ( "mysqlNamePassword.properties");.
Properties.load (inStream);
} the finally {
return properties;
}

}
which are used to load the contents of the document reading method in a manner key properties of the incoming object, the contents of the file must be a

= Test name
Age = 18 is
such a format
can not be double quotation marks, apostrophes

Guess you like

Origin www.cnblogs.com/xuzhiwen/p/11610949.html