流把對(duì)數(shù)據(jù)的讀寫進(jìn)行人為抽象,抽象成數(shù)據(jù)在管道中流動(dòng)
流是單向的
輸入流,只能用來(lái)讀取數(shù)據(jù)
輸出流,只能用來(lái)輸出數(shù)據(jù)
流只能順序讀寫數(shù)據(jù)
——流只能一次性從頭到尾流動(dòng)
—— 流動(dòng)過(guò)的數(shù)據(jù)不能重復(fù)流動(dòng),只能是一次性的,最后一個(gè)字節(jié)讀完,流就沒(méi)用了
——重復(fù)讀寫數(shù)據(jù),只能新建流,從頭讀寫

流
InputStream/OutputStream
字節(jié)流的抽象父類
抽象類不能創(chuàng)建對(duì)象,如果要?jiǎng)?chuàng)建對(duì)象,只能創(chuàng)建子類對(duì)象
public abstract class InputStream implements Closeable {}
public abstract class OutputStream implements Closeable, Flushable {}
方法:
3個(gè)重載的write方法
write(int b)
write(byte[])
write(byte[],start,length)
flush()刷出緩存數(shù)據(jù)
2個(gè)重載的read方法
read()讀一個(gè)字節(jié)
read(byte[])讀一批
available()剩余可讀取的字節(jié)數(shù)量
public int available() throws IOException {
return 0;
}