import java.util.Properties; import java.io.FileInputStream;public class Test { public static void main(String[] args) throws Exception{ FileInputStream inStream = new FileInputStream("./db.properties"); Properties property = new Properties();
property.load(inStream);//把指定的流加载到内存中来 String db=property.getProperty("db");//从内存中读出Key为db的Value //中文编码转换 /*db= new String( db.getBytes("ISO8859-1"),"UTF8");*/ System.out.println(db); System.out.println(property.getProperty("username"));
import java.util.Properties;
import java.io.FileInputStream;public class Test {
public static void main(String[] args) throws Exception{
FileInputStream inStream = new FileInputStream("./db.properties");
Properties property = new Properties();
property.load(inStream);//把指定的流加载到内存中来
String db=property.getProperty("db");//从内存中读出Key为db的Value
//中文编码转换
/*db= new String(
db.getBytes("ISO8859-1"),"UTF8");*/
System.out.println(db);
System.out.println(property.getProperty("username"));
/*db.properties里的内容,它里面存的是键值对
*db=oracle
*url=192.16.0.126
*username=openlab
*password=open123
*
*/
}}
jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost/cmsdb?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8jdbc.username=rootjdbc.password=123hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect