一直覺得輸入輸出流是個令人頭痛的問題,今天下午,看完了《21》天上的一個例子,總結了一下。首先總結一下IO類
/**/ /* *以下是基于字節流的文件拷貝,可以兼容字符文件的拷貝,例如拷貝 */ ???? 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();