java之其他流

在这里插入图片描述
1、编写程序,通过打印流完成复制文本文件
public class demo {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(“内存操作流.java”));
PrintWriter printWriter = new PrintWriter(new FileOutputStream(“aa.java”),true);
String line=null;
while ((line=reader.readLine())!=null){
printWriter.println(line);
}
reader.close();
printWriter.close();

3、public class demo11 {
public static void main(String[] args) throws IOException,ClassNotFoundException{
//序列化:把对象保存到,硬盘上
//反序列化:把对象读取到内存中
//ObjectOutputStream 序列化流
// ObjectInputStream 反序列化流
show();
show2();

}

private static void show2()throws IOException,ClassNotFoundException {
Student1 student1 = new Student1(“lishi”,23);
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(“student.txt”));
out.writeObject(student1);
out.close();
}

private static void show()throws IOException,ClassNotFoundException {
ObjectInputStream stream = new ObjectInputStream(new FileInputStream(“Student1”));
Object obj = stream.readObject();
Student1 student1= (Student1) obj;
System.out.println(student1.getName());
System.out.println(student1.getAge());
}
}

发布了29 篇原创文章 · 获赞 0 · 访问量 340

猜你喜欢

转载自blog.csdn.net/weixin_45673369/article/details/103172903
今日推荐