BufferedInputStream和BufferedOutputStream過濾流的使用

從test.txt文件內容讀取出來

public class BuferedDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedInputStream bi=null;
		
		try {
			bi=new BufferedInputStream(new FileInputStream("F:\\test.txt"));
			int result=0;
			byte[] by=new byte[1024];
			System.out.print("文件內容的結構如下:");
			while ((result=bi.read(by))>0) {
				System.out.print(new String(by, 0, result));
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			try {
				bi.close();
				
			} catch (IOException e2) {
				// TODO: handle exception
				e2.printStackTrace();
			}
		}
	}

}
BufferedOutputStream和上面類似

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章