类的反射及xml文件的解析
类的反射
xml文件的解析
.properties||.xml配置文件的创建及读取内容
//创建对象 Properties properties = new Properties(); //存储 properties.setProperty("driver", "com.mysql.jdbc.Driver"); properties.setProperty("url", "jdbc:mysql://localhost:3306/userdb"); properties.setProperty("user", "root"); properties.setProperty("password", "123456"); //存储到绝对路径盘符 properties.store(new FileOutputStream(new File("e://home/soldier/SOLDIER/idea_project/Order/jdbc.properties")), "db配置"); properties.storeToXML(new FileOutputStream(new File("e://home/soldier/SOLDIER/idea_project/Order/c3p0.xml")), "数据库连接池"); //使用相对路径-->当前工程 properties.store(new FileOutputStream(new File("jdbc.properties")), "db配置"); properties.storeToXML(new FileOutputStream(new File("c3p0.xml")), "数据库连接池"); //使用相对路径-->当前工程下的xxx properties.store(new FileOutputStream(new File("src/com/soldier/db/jdbc.properties")), "db配置"); //读取绝对路径 properties.load(new FileReader("e://home/soldier/SOLDIER/idea_project/Order/jdbc.properties")); //使用相对路径-->当前工程 properties.load(new FileReader("jdbc.properties")); //使用相对路径-->当前工程下的xxx properties.load(new FileReader(new File("src/com/soldier/db/jdbc.properties"))); //如果没有就输出后面的默认值 System.out.println(properties.getProperty("user", "null"));