一直覺得輸入輸出流是個令人頭痛的問題,今天下午,看完了《21》天上的一個例子,總結了一下。
首先總結一下IO類

















?2

?3

?4


?5

?6

?7

?8

?9

10

11

12

13

14

15

16

17

18

19

20

21

22



23

24



25

26



27

28

29

30

31

32

33

34

35

36

37

/**/
/*
*以下是基于字節流的文件拷貝,可以兼容字符文件的拷貝,例如拷貝
*/
????
boolean
?eof?
=
?
false
;??
//
文件是否讀取完畢
?????
int
?intChar?
=
?
0
;????
//
文件是否已經讀到尾
????
//
文件輸入流????????
?????File?source?
=
?
new
?File(String?sourceName);
????FileInputStream?fis?
=
?
new
?FileInputStream(source);
????BufferedInputStream?bis
=
?
new
?BufferedInputStream(fis);
????
//
文件輸出流
????File?destination?
=
?
new
?File(String?destinationName);
????FileOutputStream?fos?
=
?
new
?FileOutputStream(destination);
????BufferedOutputStream?bos?
=
?
new
?BufferedOutputStream(fos);
????
do
{
????????intChar?
=
?bis.read();
????????
if
(intChar?
!=
?
-
1
)
{
????????????bos.writer(intChar);
????????}
else
{
??????????eof?
=
?
true
;
????????}
????}
while
(
!
eof);
?????????
??????? bis.flush();
??????? bos.close();
??????? bis.close();