properties文件:项目当中比较常见的配置文件。
特点:以键值对的形式保存数据
作用:通过将系统配置定义在properties文件的形式来实现代码解耦。
解析:
Properties properties = new Properties();
File file = new File("log4j.properties");
InputStream inStream = new FileInputStream(file);
properties.load(inStream);
获取:
properties结构:跟map一样是属于字典类型的数据结构。
取数据:properties.getProperty(key)。
IO流:
流向:
输入流 read 读
InputStream
FileInputStream
FileReader
输出流 write 写
OutputStream
FileOutputStream
FileWriter
类型
字节流(读写任意文件)
FileInputStream
FileOutputStream
字符流(只能读写纯文本文件)中文
FileReader
FileWriter
关流
用完之后关闭流。
File FileInputStream(读) FileOutputStream(写)
编译时异常
如果不处理,代码就报错。IO异常。
必须要处理。未雨绸缪。
如何处理:
1、throws Exception 往外抛出异常。
2、try {
//可能会报错的代码
} catch 捕获异常 {
原文:https://www.cnblogs.com/zhiyu07/p/14287280.html