IO流資料讀寫

2021-09-19 06:13:00 字數 717 閱讀 2842

io流資料讀寫

// 建立檔案b.txt

string file = "f:\\ab\\input\\b.txt";

file file2 = new file(file);

file2.createnewfile();

// 位元組輸出流,第二個參,表示不覆蓋,末尾追加

fileoutputstream outputstream = new fileoutputstream(file, true);

// 寫

string data = "123456";

outputstream.write(data.getbytes(), 0, data.length());

// 位元組輸入流 ,用於讀取資料

fileinputstream inputstream = new fileinputstream(file);

// 建立乙個水桶,用於存放讀的資料

byte b = new byte[1024];

int hasnum = -1;

string line = "";

while ((hasnum = inputstream.read(b)) != -1)

system.out.println(line);

//關流

inputstream.close();

IO流檔案讀寫

p1 開啟檔案 讀檔案 關閉檔案的典型方法 try f open d test.txt r print f.read finally if f f.close p2 推薦的簡潔寫法,不必顯示的關閉檔案描述符 open返回的物件在python中稱作file like 物件,可以是位元組流 網路流 自定...

I O流 檔案讀寫

流 流 即是流動的意思,是物質從一處向另一處流動的過程。c 流是指資訊從外部輸入裝置 鍵盤等 向計算機內部 如記憶體 輸入和從記憶體向外部輸出裝置 顯示器 輸出的過程。這種輸入輸出的過程被形象的成為 流 為了實現這種流動,c 定義了i o標準庫,這些每個類都成為流 流類,完成一些功能。define ...

IO流的讀寫

測試了一些用普通的bufferreader讀太慢了,還是用位元組陣列輸出流比較快,測試nio比它還慢幾十毫秒如果讀寫8m的txt檔案示例 string newpath long start system.currenttimemillis mapmap xmlreader.viewxml file ...