FileReader和BufferedReader

 BufferedReader   由Reader类扩展而来,提供通用的缓冲方式文本读取,而且提供了很实用的readLine,读取分行文本很适合,BufferedReader是针对Reader的,不直接针对文件,也不是只针对文件读取。

    FileReader是由java.io.InputStreamReade扩展来的,是针对文件读取的。

    实际使用时往往用 BufferedReader bfrTemp = new BufferedReader(new FileReader("test.conf"));先建立一个文件reader,再用BufferedReader读。

    FileInputStream   扩展自java.io.InputStream,InputStream提供的是字节流的读取,而非文本读取,这是和Reader类的根本区别。用Reader读取出来的是char数组或者String   ,使用InputStream读取出来的是byte数组。



public interface worker {
	public void dosomework();
}

public class Carpenter implements worker {
	public void dosomework() {
		System.out.println("修门窗");
	}


}

public class Plumber implements worker {
	public void dosomework() {
		System.out.println("修水管");
	}

}
public class Aworker implements worker {
	private worker worker1;

	public Aworker(worker worker1) {
		this.worker1 = worker1;
	}

	public void dosomework() {
		System.out.println("Hello");
		worker1.dosomework();
	}

}

public class Test {

	public static void main(String[] args) {
		Plumber plumber = new Plumber();
		Aworker work = new Aworker(plumber);
		work.dosomework();
		Carpenter carpenter = new Carpenter();
		Aworker work1 = new Aworker(carpenter);
		work1.dosomework();
	}

}



你可能感兴趣的