Print流
Print 打印流:只做输出没有输入
Print流单向输出(从服务器端内容向客户端浏览器打印输出网页内容)
打印流分为字节打印流和字符打印流
PrintWriter:字符打印流
print方法可以打印各种类型数据
PrintWriter print = new PrintWriter("E:\\a.html");
print.print("<b>aaa</b>");
print.print("<b>bbbbb</b>");
print.close();
对象输入输出流
对象的输入输出流 : 主要的作用是用于写入对象信息与读取对象信息。 对象信息一旦写到文件上那么对象的信息就可以做到持久化了.
对象的输出流: ObjectOutputStream 对象的输入流: ObjectInputStream
要将序列化之后的对象保存下来,需要通过对象输出流(ObjectOutputStream)将对象状态保存,之后再通过对象输入流(ObjectInputStream)将对象状态恢复。
对象序列化
对象序列化:输出对象信息到指定文件,长久保存,这个过程称为对象的序列化.
public static void main(String[] args) throws IOException {
//输出对象信息到指定文件,长久保存,这个过程称为对象的序列化
//writeObject()方法可以直接将对象保存到输出流中
FileOutputStream fout = new FileOutputStream("E:\\aa.obj");
ObjectOutput objo = new ObjectOutputStream(fout);
Date date = new Date();
String s = "adad";
objo.writeObject(date);
objo.writeObject(s);
Student student = new Student("aaa",12);
objo.writeObject(student);
objo.close();
}
对象反序列化:使用对象的输出流,将文件中序列化的对象信息读取生成对象的过程称为对象的反序列化.
public static void main(String[] args) throws IOException, ClassNotFoundException {
//使用对象的输入流,将文件中序列的对象信息,读取生成对象的过程称为对象反序列化
//readObject()方法可以直接读取一个对象
FileInputStream file1 = new FileInputStream("E:\\aa.obj");
ObjectInput objin = new ObjectInputStream(file1);
Date d = (Date) objin.readObject();
String ss = (String) objin.readObject();
System.out.println(d);
System.out.println(ss);
Student student1 =(Student) objin.readObject();
System.out.println(student1);
objin.close();
}