要在spring 中配置参数 如 jdbc.driverClassName=org.hsqldb.jdbcDriver jdbc.url=jdbc:hsqldb:hsql://localhost:9002 jdbc.username=sa jdbc.password= 必须在配置加入 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 用来读取相应的properties 如 WEB-INF/jdbc.properties 本文来自ChinaUnix博客,如果查...
by zuomo - Java文档中心 - 2008-04-22 10:57:48 阅读(675) 回复(0)
我有一个.properties file.文件格式如下: userid=test1 password=test2 path=c:\test .... 我应该如何读取这个文件,将test1赋值给变量$userid, 将test2赋值给变量$pwd, 将c:\test赋值给变量$path. 另外一个文件格式如下: version=r10.03.00.00|r10.04.00.00|r10.05.00.10... 我应该如何读取这个文件,将r10.03.00.00赋值给变量$v1, 将r10.04.00.00赋值给变量$v2, 将r10.05.00.10赋值给变量$v3.......... 谢谢大家帮忙 :(
public String getPara(String ParaName) { FileName = "../../DBConfig.property"; properties prop = new properties(); try { InputStream is = getClass().getResourceAsStream(FileName); prop.load(is); if(is!=null) is.close(); } catch(Exception e) { return "Error!"; } return prop.ge...
1、使用java.util.properties类的load()方法 例: InputStream in = lnew BufferedInputStream(new FileInputStream(name)); properties p = new properties(); p.load(in); 2、使用java.util.ResourceBundle类的getBundle()方法 例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault() ); 3、使用java.util.PropertyResourceBundle类的构造函数 例: InputStream in = new BufferedInputStream(new ...
在我们平时写程序的时候,有些参数是经常改变的,而这种改变不是我们预知的。比如说我们开发了一个操作数据库的模块,在开发的时候我们连接本地的数据库那么 IP ,数据库名称,表名称,数据库主机等信息是我们本地的,要使得这个操作数据的模块具有通用性,那么以上信息就不能写死在程序里。通常我们的做法是用配置文件来解决。 各种语言都有自己所支持的配置文件类型。比如 Python ,他支持 .ini 文件。因为他内部有一个 ConfigP...
在我们平时写程序的时候,有些参数是经常改变的,而这种改变不是我们预知的。比如说我们开发了一个操作数据库的模块,在开发的时候我们连接本地的数据库那么 IP ,数据库名称,表名称,数据库主机等信息是我们本地的,要使得这个操作数据的模块具有通用性,那么以上信息就不能写死在程序里。通常我们的做法是用配置文件来解决。 各种语言都有自己所支持的配置文件类型。比如 Python ,他支持 ....
1。使用java.util.properties类的load()方法示例:InputStreamin=lnewBufferedInputStream(newFileInputStream(name));propertiesp=newproperties();p.load(in); 2。使用java.util.ResourceBundle类的getBundle()方法示例:ResourceBundlerb=ResourceBundle.getBundle(name,Locale.getDefault()); 3。使用java.util.PropertyResourceBundle类的构造函数示例:InputStreamin=newBufferedInputStream(newFileInputStream(nam...
在spring中,使用PropertyPlaceholderConfigurer和PropertyOverrideConfigurer可以在XML配置文件中加入外部属性文件 但使用这种方式,有一些需要注意的地方 1.首先在主类中,需要使用ClassPathXmlApplicationContext来读取spring配置xml文件 如: ApplicationContext context = new ClassPathXmlApplicationContext("example4/appcontext.xml"); HelloWorld hw = (HelloWorld)context.getBean("fileHelloWorld"); log.info(hw.get...
1. jdbc.properties database.url=jdbc:mysql://localhost/smapledatabase.driver=org.gjt.mm.mysql.Driverdatabase.user=rootdatabase.password=star1xing 2.conf.xml com/starxing/test/jdbc.properties ${database.url} ${database.driver} ${database.user} $...
1. jdbc.properties database.url=jdbc:mysql://localhost/smapledatabase.driver=org.gjt.mm.mysql.Driverdatabase.user=rootdatabase.password=star1xing 2.conf.xml com/starxing/test/jdbc.properties ${database.url} ${database.driver} ${database.user} $...
使用J2SE API读取properties文件的六种方法 1。使用java.util.properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name)); properties p = new properties(); p.load(in); 2。使用java.util.ResourceBundle类的getBundle()方法 示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault()); 3。使用java.util.PropertyRe...