輸入流:
int b;
fileinputstreamin=
newfileinputstream
(string filepath)
;b =in.
read()
;//將讀取到的乙個位元組存到b中 讀取到檔案末尾會返回-1
in.close;
//關閉流
輸出流:
string s;
fileoutputstream
out=
newfileoutputstream
(string filepath)
;byte
b = s.
getbytes()
;for
(int i =
0; i < b.length; i++
)out
.close;
//關閉流
fileinputstreamin=
newfileinputstream
(string filepath)
;fileoutputstream
out=
newfileoutputstream
(string filepath)
;int len;
byte
buff =
newbyte
[1024];
while
(len =in.
read
(buff)!=-
1)in.close;
out.close;
這樣可加快速度
bufferedinputstream bis =
newbufferedinputstream
(new
fileinputstream
(string filepath));
bufferedoutputstream bos =
newbufferedoutputstream
(new
bufferedoutputstream
(string filepath));
int len;
while
((len = bis.
read()
)!=-1
) bis.close;
bos.close;
輸入流:
filereader reader =
newfilereader
(string filepath)
;int ch;
while
((ch = reader.
read()
)!=-1
)reader.
close()
;
輸出流:
filewriter writer =
newfilewriter
(string filepath)
;string str;
writer.
write
(str)
; writer.close;
緩衝流:
bufferedreaderin=
newbufferedreader
(new
filereader
(string filepath));
bufferedwriter
out=
newbufferedwriter
(new
filewriter
(string filepath));
string line =
null;
while (
(line =in.
readline()
)!=null)in
.close()
;out
.close()
;
轉換流:
fileinputstreamin=
newfileinputstream
(string filepath)
;inputstreamreader isr =
newinputstreamreader(in
);bufferedreader br =
newbufferedreader
(isr)
;
位元組流 字元流 位元組緩衝流 字元緩衝流
位元組讀流 fileinputstream fis new fileinputstream file byte b new byte 1024 int len 0 while len fis.read b 1 字元讀流 filereader fr new filereader file char c...
位元組 字元 流
首先我們說string就是一字串,它僅僅是人們在使用中的乙個記號,它具有乙個抽象的意義,比如我定義string name devilelife 從程式上看,哦,我知道了這個字串表示乙個name,而byte則是實實在在的很具體乙個連續的儲存空間,每個byte需要乙個位元組的空間去儲存,而這個空間儲存的...
位元組流 字元流
fileoutputstream 構造 構造方法摘要 fileoutputstream file file 建立輸出流,不是以續寫方式關聯 fileoutputstream string name 建立輸出流,不是以續寫方式關聯 作用 1.建立乙個輸出流物件 2.如果你關聯的檔案,或者檔案的字串不存...