一 回顾
1.转换流 字符与字节的桥梁 可以设置其编码表
InputStreamReader 读 OutputStreamWriter 写
2.字符高效流
BufferedReader 读 BufferedWriter 写
readLine() 读取一行 newLine() 换行
3.对象流: 对象需要实现序列化的接口
ObjectInputStream 读 ObjectOutputStream 写
readObject() writerObject()
4.多方法的参数
访问修饰符 返回值类型 方法的名称(数据类型 ... 变量名) {
方法体;
return 返回值
}
5.Properties:Properties 类表示了一个持久的属性集
public Object setProperty(String key,String value) 设置值
public String getProperty(String key) 获取值
public Set<String> stringPropertyNames() 获取所有的键
public void load(InputStream inStream) 将文件的信息加载到Properties对象中
public void store(OutputStream out) 将Properties对象的数据写入到文件中
6.工具类:
A.私有的属性
B.私有的构造方法 ==>只能在本类实例化对象
C.公有的方法 ==>对外提供访问
D.定义一个方法根据键来获取值的方法
二 作业01
step03 代码-工具类
package com.qf.demo01;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertiesUtils {
private static PropertiesUtils prop;
private Properties p;
private PropertiesUtils(){
try {
p = new Properties();
p.load(new FileInputStream("admin.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static PropertiesUtils getInstance(){
return prop = new PropertiesUtils();
}
public String getValue(String key){
return p.getProperty(key);
}
}
step04-学生类
package com.qf.demo01;
import java.io.Serializable;
public class Students implements Serializable {
private String name;
private int age;
public Students() {
}
public Students(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Students{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
step05 测试类
package com.qf.demo01;
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException, ClassNotFoundException {
String name = PropertiesUtils.getInstance().getValue("name");
String age = PropertiesUtils.getInstance().getValue("age");
Students s = new Students();
s.setName(name);
s.setAge(Integer.parseInt(age));
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("1.txt"));
oos.writeObject(s);
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("1.txt"));
Students o = (Students) ois.readObject();
System.out.println(o);
ois.close();
}
}
要在配置文件以万国码存储,这里姓名才显示正确
Students{name='Îľ²', age=18}
三 线程
3.1 线程的概念
1.程序:一个固定逻辑与数据的集合就是程序例如俄罗斯方块贪吃蛇
2.cpu:中央处理器 主要用于协调