jav學習之 IO流

2021-07-25 16:44:59 字數 2421 閱讀 9245

/*1.流的分類

* 按照資料流向的不同:輸入流 輸出流

* 按照處理資料的單位的不同:位元組流 字元流(處理的檔案文字)

* 按照角色的不同,節點流(直接作用於檔案)處理流

* 2.io的體系

* 抽象基類 節點流(檔案流) 緩衝流(處理流的一種)

* inputstream fileinputstream bufferedinputstream

* outputstream fileoutputstream bufferedoutputstream

* reader filereader bufferedreader

* writer filewriter bufferedwriter

*/public class testfileinputoutputstream catch (exception e) finally catch (ioexception e)

}} }

@test

public void testfileinputstream1()

}} catch (ioexception e) finally catch (ioexception e)

}} }

}

/*

* 標準的輸入輸出流:

* 標準的輸出流:system.out

* 標準的輸入流:system.in

* * 題目:

* 從鍵盤輸入字串,要求將讀取到的整行字串轉成大寫輸出。然後繼續進行輸入操作,

* 直至當輸入「e」或者「exit」時,退出程式。

*/@test

public void test2()

string str1 = str.touppercase();

system.out.println(str1);

}} catch (ioexception e) finally catch (ioexception e)

}} }

/** 如何實現位元組流與字元流之間的轉換:

* 轉換流:inputstreamreader outputstreamwriter

* 編碼:字串 --->位元組陣列

* 解碼:位元組陣列--->字串

*/@test

public void test1()

}catch (ioexception e) finally catch (ioexception e)

}if(br != null) catch (ioexception e)

}}

}}

public class testobjectinputoutputstream catch (exception e) finally catch (ioexception e) 

}}

} // 物件的序列化過程:將記憶體中的物件通過objectoutputstream轉換為二進位製流,儲存在硬碟檔案中

@test

public void testobjectoutputstream() catch (ioexception e) finally catch (ioexception e)

}} }}

/* * 要實現序列化的類: 1.要求此類是可序列化的:實現serializable介面

* 2.要求類的屬性同樣的要實現serializable介面

* 3.提供乙個版本號:private static final long serialversionuid

* 4.使用static或transient修飾的屬性,不可實現序列化

*/class person implements serializable

@override

public string tostring()

} class pet implements serializable

@override

public string tostring()

}

C 學習之IO流

主要i o流類 格式化i o 1 格式化函式 成員函式 cout 10 3.0 endl cout.precision 10 cout 10 3.0 endl 3333 2 流控制符 全域性函式 include cout 10 3.0 endl cout setprecision 10 10 3.0...

Java學習筆記之 IO流之列印流

列印流 三個常量 1.system.in 輸入流 2.system.out 輸出流 除錯 列印日誌 3.system.err 列印出的顏色是紅色的 重定向setin setout seterr 下面為demo public class printstreamdemo01 我們可以看到檔案如下 然後我...

C 學習筆記之I O流

c 提供的i o流類庫含有兩個平行基類 streambuf 和 ios,所有的流類都是由它們派生出來的。ios類包含四個直接派生類 輸入流類istream,輸出流類ostream,檔案流類fstreambase,串流類strstreambase。i o流類庫最主要的標頭檔案iostream,它支援c...