IO流例項 位元組流

2021-09-27 04:30:31 字數 1294 閱讀 8239

從硬碟存在的乙個檔案讀取內容到程式,需要使用fileinputstream

@test

public void testfileinputstream1() throws ioexception

*/int b;

while ((b = fis.read()) != -1)

// 4.關閉相應的流

fis.close();

}

// 使用try-catch的方式處理異常可以保證流的關閉一定執行

@test

public void testfileinputstream2()

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

} }

@test

public void testfileinputstream3()

*/string str = new string(b, 0, len);

system.out.println(str);

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

} }

// fileoutputstream

@test

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

} }

// 從硬碟讀取乙個檔案,並寫入到另外乙個位置(複製)

@test

public void testfileoutputstream1()

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

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

}} }

@test

public void method()

public void copyfile(string source,string dest)

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

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

}} }

IO流 位元組流

位元組輸出流outputstream 此抽象類,是表示輸出位元組流的所有類的超類。操作的資料都是位元組,定義了輸出位元組流的基本共性功能方法。輸出流中定義的方法 close 關閉輸出流並釋放與此輸出流有關的所有系統資源 flush 重新整理此輸出流並強制寫出所有緩衝的輸出位元組 write byte...

IO流位元組流

io流就是裝置之間的資料傳輸 位元組流 任意型別的檔案都能讀寫 位元組流的 抽象 基類 inputstream 輸入流 outoutstream 輸出流 fileoutputstream的三個write 方法 public void write int b 寫乙個位元組 超過乙個位元組 砍掉前面的位...

IO流 位元組流

io流分類 按資料的流向 輸入流 讀資料 輸出流 寫資料 按資料型別 位元組流 字元流 一般來說,我們說io流的分類是按照資料型別來分的。那麼這兩種流都在什麼情況下使用呢?如果資料通過windows子代的記事本軟體開啟,我們還可以讀懂裡面的內容,就是用字元流,否則使用位元組流。如果你不知道該使用哪種...