增强功能:不改变原有功能实现,灵活的添加新的功能
输入输出流的一套包装类,就是装饰器。
代码结构
源码
package com.myspringboot.shejimoshi.zhuangshiqi;
import java.io.*;
public class Main {
public static void main(String[] args) {
File file = new File("D:\\javatest\\1.txt");
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(osw);) {
bw.write("decorator");
bw.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}