Txt streamreader strm finopentext string sline do

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: .IO.TextWriter Abstract base class for writing strings to streams Includes placeholder-formatted strings System.IO.StreamWriter (inherits TextWriter) W rites strings to streams with encoding support System.IO.StringWriter Simulates streams--writes on an output string 24 I/O and Networking Stream Reader Example // Reading Text Files NewFile(“C:\ Projects\ File fIn = NewFile(“C:\\dotNet Projects\\Readme.txt”); StreamReader strm = fIn.OpenText(); String sLine; do { sLine = strm.ReadLine(); AddItem(sLine); } while (sLine != null); Strm.close(); I/O and Networking Stream Writer Example public class MyWriter { private Stream s; public MyWriter(Stream stream) { s = stream; } public void WriteDouble(double myData) { byte b = myData.GetBytes(); // GetBytes is a binary representation of // a double data type. s.Write(b,0,b.Length); } public void Close() { s.Close(); } } 25 Disk Files Use the FileStream class (along with others) Three steps you'll need to perform Open a file (use the constructor or static method) Read or write to the file For simple binary data, use the Stream class...
View Full Document

This note was uploaded on 04/04/2014 for the course CS 5950 taught by Professor Staff during the Summer '08 term at Western Michigan.

Ask a homework question - tutors are online