【文章內(nèi)容簡介】
= (buffer, 0, (int))。 string text = (buffer, 0, count)。 ()。 Streams(bytelevel I/O) ? Streamderived classes提供一個一般的介面來對不同的儲存媒介作 byteoriented存取 ? 如果我們面對的是 bytes那當然沒有問題 , 但如果我們需要讀取和寫入 two bytes per character的Unicode時該如何 ? 或許你還可能讀取或寫入integers, floatingpoint values, or strings in their native mode ? 因此你可能想要有更 highe level的抽象概念,像是讀取或寫入多行文字資料 Three General Categories ? Streams(bytelevel I/O) ? Readers and writers ? File system Readers and writers ? 在 higher level讀取和寫入,例如傳輸 value data types, Unicode characters, strings, and lines of text Readers and writers ? StreamReader’s constructor StreamReader fs = new StreamReader(Stream)。 StreamReader fs = new StreamReader(String)。 StreamReader fs = new StreamReader(Stream, Encoding)。 StreamReader fs = new StreamReader(String, Encoding)。 Readers and writers ? 第一種 constructor要傳入 Stream的參數(shù),因此先利用 FileStream開啟一檔案,再當作參數(shù)傳入 ? 第二種 constructor較簡單 , 直接傳入檔案名稱及路徑即可 FileStream f = new FileStream(@.\, )。 StreamReader sr = new StreamReader(f) StreamReader sr = new StreamReader((@.\) Readers and writers ? StreamReader Method Description Read() Reads the next character from the input stream and advances the character position by one character Read(byte[], int32, int32) Reads a maximum of count characters from the current stream into buffer, beginning at index. ReadLine() Reads a line of characters from the current stream and returns the data as a string ReadToEnd() Reads the stream from the current position to the end of the stream Close() Closes the StreamReader object and the underlying stream, and releases any system resources associated with the reader Readers and writers ? 會出現(xiàn)一個 messagebox視窗顯示 中的所有文字資料 StreamReader sr = new StreamReader(@.\)。 (())。 ()。 Readers and writers ? StreamWriter’s constructor StreamWriter fs = new StreamWriter(Stream)。 StreamWriter fs = new Stre