-
Properties(配置文件)
可持久化的映射类,继承Hashtable,键和值都应该是字符串,生成的配置文件的后缀一定是.properties,默认编码是西欧编码。中文转不了,按u16进行编码,配置文件可以随意改动。
public class PropertiesDemo1 {
public static void main(String[] args) throws IOException {
//创建对象
Properties p1 = new Properties();
//添加元素----键和值(都是字符串)
p1.setProperty("name","lili");
p1.setProperty("gender","nv");
p1.setProperty("age","18");
//把要存储的内容传输到配置文件中 --- 配置文件后缀,必须是 .properties
//第二个参数 --- 文件的内容解释
p1.store( new FileOutputStream( "p.properties" ), "xxx");
}
}
public class PropertiseDemo2 {
public static void main(String[] args) throws IOException {
//创建对象
Properties p = new Properties();
//加载指定配置文件
p.load(new FileInputStream("p.properties"));
//获取配置文件内容,根据键获取值
System.out.println(p.getProperty("name"));
System.out.println(p.getProperty("name","fafa"));//还是lili
//快速知道配置信息,列出配置文件信息
//可以自己改动配置文件p.properties
p.list(System.out);
}
}
-
Junit(单元测试)
导入测试库,可以支持单元测试的(三无)方法----没有static、没有返回值、没有参数
-
断言(assert)
对程序结果进行预测性的判断 assert---关键字