Properties文件使用演示
2020-01-15 11:54
1506 查看
jdbc.properties文件
连接数据库的配置文件
driver=com.mysql.jdbc.Driver #连接数据库的驱动器 url=jdbc:mysql://localhost:3306/mydb #连接数据库的路径 username=root #数据库的用户名 password=123456 #数据库的密码
Properties文件使用演示
package com.hashtable; import java.io.FileInputStream; import java.util.Properties; import java.util.ResourceBundle; import org.junit.Test; // Properties使用演示 public class PropertiesTest { // 加载properties属性文件方式三 @Test public void test04() { ResourceBundle rb = ResourceBundle.getBundle("jdbc");//文件名为jdbc.properties String driver = rb.getString("driver"); String url = rb.getString("url"); System.out.println(driver); System.out.println(url); } // 加载properties属性文件方式二 @Test public void test03() throws Exception { Properties prop = new Properties(); prop.load(PropertiesTest.class.getClassLoader() .getResourceAsStream("jdbc.properties")); String driver = prop.getProperty("driver"); String url = prop.getProperty("url"); System.out.println(driver); System.out.println(url); } // 加载properties属性文件方式一 @Test public void test02() throws Exception { Properties prop = new Properties(); prop.load(new FileInputStream("src/jdbc.properties")); String driver = prop.getProperty("driver"); String url = prop.getProperty("url"); System.out.println(driver); System.out.println(url); } @Test public void test01() { Properties prop = new Properties(); prop.setProperty("aa", "hello"); prop.setProperty("bb", "world"); System.out.println(prop.getProperty("aa")); System.out.println(prop.getProperty("bb")); } }
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 使用J2SE API读取Properties文件的六种方法
- 使用J2SE API读取Properties文件的六种方法
- Struts资源文件(application.properties)的使用
- Java中封装配置文件(1)-使用Properties (转)
- spring对AOP的支持(使用Spring的配置文件来演示)
- java中的Properties文件操作使用举例
- java 读取properties文件,运用 使用properties
- 在Spring配置文件中使用properties文件
- 使用J2SE API读properties文件的六种方法
- JAVA学习提高之----使用J2SE API读properties文件的六种方法
- Java中封装配置文件使用Properties
- 使用帮助类读取配置文件(*.properties)
- Java 使用DataInputStream将数据写入文件,使用FileReader读取演示
- Android下使用Properties文件保存程序设置
- Spring 使用配置文件读取jdbc.properties
- 使用J2SE API读取Properties文件的六种方法
- 使用J2SE API读取Properties文件的六种方法
- 使用Properties文件配置实例的创建
- 谈Java Properties配置文件, 是J2EE容器的命令行绑定, 还是使用Deploy自适应的绑定?
- 使用J2SE API读取Properties文件的六种方法