处理流使用实例:BufferedReader 字符输入处理流
BufferedReader类里面有个方法叫readLine(),读取一行数据并返回这行数据
生成BufferedReader对象的方法:
BufferedReader br = new BufferedReader(new FileReader(“C:/”))
import java.io.*;class Test{public static void main(String args[]){FileReader fr = null;BufferedReader br =null;try{fr = new FileReader("F:/Android/Java4Android/34/src/users.txt");br = new BufferedReader(fr);String s = br.readLine();System.out.PRintln(s);}catch(Exception e){System.out.println(e);}finally{try{fr.close();br.close();}catch(Exception e){System.out.println(e);}}}}
装饰者模式举例:
interface Worker{public void doSomeWork();}
class Carpenter implements Worker{public void doSomeWork(){System.out.println("修门窗");}}
class Plumber implements Worker{public void doSomeWork(){System.out.println("修水管");}}
class Aworker implements Worker{private Worker worker;public Aworker(Worker aworker){this.worker = aworker;}public void doSomeWork(){System.out.println("你好");worker.doSomeWork();}}
class Test{public static void main(String args[]){Worker carpenter = new Carpenter();Aworker carpenterWorker = new Aworker(carpenter);carpenterWorker.doSomeWork();Worker plumber = new Plumber();Aworker plumberWorker = new Aworker(plumber);plumberWorker.doSomeWork();}}
新闻热点
疑难解答