- 处理流使用实例
- “装饰者(Decorator)”模式
- 节点流与处理流的关系
BufferedReader生成对象方法
BufferedReader in = new BUfferedReader(newFlieReader("foo.in"));
import java.io.*; //导入IO流 class Test{ public static void main(String args[]){ FileReader fileReader = null;//声明FileReader对象 BufferedReader buffereReader = null; try{ fileReader = new FileReader("e:/src/user.txt"); buffereReader = new BufferedReader(fileReader); String line = null; while(true){ //循环读取每一行 line = buffereReader.readLine();//读取一行 if(line == null){ break; } System.out.println(line); } } catch(Exception e){ System.out.println(e); } finally{ try{ fileReader.close(); buffereReader.close(); }catch(Exception e){ System.out.println(e); } } } }
==================================================================
装饰者模式
interface Worker{ public void doSomeWork(); }
class Plumber implements Worker{ public void doSomeWork(){ System.out.println("水管工"); } }
class Carpenter implements Worker{ public void doSomeWork(){ System.out.println("木工修门窗"); } }
class AWorker implements Worker{ private Worker worker; public AWorker(Worker worker){ this.worker = worker; } public void doSomeWork(){ System.out.println("你好"); worker.doSomeWork(); } }
class Test01{ public static void main(String args[]){ //生成一个A公司水管工对象 Plumber plumber = new Plumber(); AWorker aWorker = new AWorker(plumber); aWorker.doSomeWork(); } }
时间: 2024-12-17 08:14:44