<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FFile_Stream%2FStream_Read_Write</id>
		<title>Csharp/C Sharp/File Stream/Stream Read Write - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FFile_Stream%2FStream_Read_Write"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/File_Stream/Stream_Read_Write&amp;action=history"/>
		<updated>2026-04-30T01:39:38Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/File_Stream/Stream_Read_Write&amp;diff=1324&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/File_Stream/Stream_Read_Write&amp;diff=1324&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:19Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/File_Stream/Stream_Read_Write&amp;diff=1325&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/File_Stream/Stream_Read_Write&amp;diff=1325&amp;oldid=prev"/>
				<updated>2010-05-26T11:45:40Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==A help program that uses a disk file     to store help information==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# A Beginner&amp;quot;s Guide&lt;br /&gt;
By Schildt&lt;br /&gt;
Publisher: Osborne McGraw-Hill&lt;br /&gt;
ISBN: 0072133295&lt;br /&gt;
*/&lt;br /&gt;
/*   &lt;br /&gt;
   Project 11-2   &lt;br /&gt;
   &lt;br /&gt;
   A help program that uses a disk file &lt;br /&gt;
   to store help information. &lt;br /&gt;
*/   &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
using System.IO;  &lt;br /&gt;
 &lt;br /&gt;
/* The Help class opens a help file, &lt;br /&gt;
   searches for a topic, and then displays &lt;br /&gt;
   the information associated with that topic. */  &lt;br /&gt;
class Help { &lt;br /&gt;
  string helpfile; // name of help file &lt;br /&gt;
 &lt;br /&gt;
  public Help(string fname) { &lt;br /&gt;
    helpfile = fname; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  // Display help on a topic. &lt;br /&gt;
  public bool helpon(string what) {  &lt;br /&gt;
    StreamReader helpRdr; &lt;br /&gt;
    int ch; &lt;br /&gt;
    string topic, info; &lt;br /&gt;
 &lt;br /&gt;
    try { &lt;br /&gt;
      helpRdr = new StreamReader(helpfile); &lt;br /&gt;
    } &lt;br /&gt;
    catch(FileNotFoundException exc) { &lt;br /&gt;
      Console.WriteLine(exc.Message); &lt;br /&gt;
      return false; &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
    try { &lt;br /&gt;
      do { &lt;br /&gt;
        // read characters until a # is found &lt;br /&gt;
        ch = helpRdr.Read(); &lt;br /&gt;
 &lt;br /&gt;
        // now, see if topics match &lt;br /&gt;
        if(ch == &amp;quot;#&amp;quot;) { &lt;br /&gt;
          topic = helpRdr.ReadLine(); &lt;br /&gt;
          if(what == topic) { // found topic &lt;br /&gt;
            do { &lt;br /&gt;
              info = helpRdr.ReadLine(); &lt;br /&gt;
              if(info != null) Console.WriteLine(info); &lt;br /&gt;
            } while((info != null) &amp;amp;&amp;amp; (info != &amp;quot;&amp;quot;)); &lt;br /&gt;
            helpRdr.Close(); &lt;br /&gt;
            return true; &lt;br /&gt;
          } &lt;br /&gt;
        } &lt;br /&gt;
      } while(ch != -1); &lt;br /&gt;
    } &lt;br /&gt;
    catch(IOException exc) { &lt;br /&gt;
      Console.WriteLine(exc.Message); &lt;br /&gt;
    }  &lt;br /&gt;
    helpRdr.Close(); &lt;br /&gt;
    return false; // topic not found &lt;br /&gt;
  }  &lt;br /&gt;
  &lt;br /&gt;
  // Get a Help topic. &lt;br /&gt;
  public string getSelection() {  &lt;br /&gt;
    string topic = &amp;quot;&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
    Console.Write(&amp;quot;Enter topic: &amp;quot;);   &lt;br /&gt;
    try {   &lt;br /&gt;
      topic = Console.ReadLine(); &lt;br /&gt;
    } &lt;br /&gt;
    catch(IOException exc) { &lt;br /&gt;
      Console.WriteLine(exc.Message); &lt;br /&gt;
      return &amp;quot;&amp;quot;; &lt;br /&gt;
    } &lt;br /&gt;
    return topic; &lt;br /&gt;
  } &lt;br /&gt;
}  &lt;br /&gt;
  &lt;br /&gt;
// Demonstrate the file-based Help system. &lt;br /&gt;
public class FileHelp {   &lt;br /&gt;
  public static void Main() {   &lt;br /&gt;
    Help hlpobj = new Help(&amp;quot;helpfile.txt&amp;quot;);  &lt;br /&gt;
    string topic; &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Try the help system. &amp;quot; + &lt;br /&gt;
                       &amp;quot;Enter &amp;quot;stop&amp;quot; to end.&amp;quot;);  &lt;br /&gt;
    do {  &lt;br /&gt;
      topic = hlpobj.getSelection();   &lt;br /&gt;
 &lt;br /&gt;
      if(!hlpobj.helpon(topic)) &lt;br /&gt;
        Console.WriteLine(&amp;quot;Topic not found.\n&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    } while(topic != &amp;quot;stop&amp;quot;); &lt;br /&gt;
  }  &lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
#if&lt;br /&gt;
if(condition) statement;&lt;br /&gt;
else statement;&lt;br /&gt;
#switch&lt;br /&gt;
switch(expression) {&lt;br /&gt;
  case constant:&lt;br /&gt;
    statement sequence  &lt;br /&gt;
    break;  &lt;br /&gt;
    // ...  &lt;br /&gt;
  }  &lt;br /&gt;
#for&lt;br /&gt;
for(init; condition; iteration) statement;  &lt;br /&gt;
#while&lt;br /&gt;
while(condition) statement;  &lt;br /&gt;
#do&lt;br /&gt;
do {  &lt;br /&gt;
  statement;  &lt;br /&gt;
} while (condition);  &lt;br /&gt;
#break&lt;br /&gt;
break; or break label;  &lt;br /&gt;
#continue&lt;br /&gt;
continue; or continue label;  &lt;br /&gt;
#goto&lt;br /&gt;
goto label;&lt;br /&gt;
 &lt;br /&gt;
*/&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A simple key-to-disk utility that     demonstrates a StreamWriter==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
/* A simple key-to-disk utility that &lt;br /&gt;
   demonstrates a StreamWriter. */ &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
using System.IO; &lt;br /&gt;
  &lt;br /&gt;
public class KtoD { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    string str; &lt;br /&gt;
    FileStream fout; &lt;br /&gt;
 &lt;br /&gt;
    try { &lt;br /&gt;
      fout = new FileStream(&amp;quot;test.txt&amp;quot;, FileMode.Create); &lt;br /&gt;
    } &lt;br /&gt;
    catch(IOException exc) { &lt;br /&gt;
      Console.WriteLine(exc.Message + &amp;quot;Cannot open file.&amp;quot;); &lt;br /&gt;
      return ; &lt;br /&gt;
    } &lt;br /&gt;
    StreamWriter fstr_out = new StreamWriter(fout); &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Enter text (&amp;quot;stop&amp;quot; to quit).&amp;quot;); &lt;br /&gt;
    do { &lt;br /&gt;
      Console.Write(&amp;quot;: &amp;quot;); &lt;br /&gt;
      str = Console.ReadLine(); &lt;br /&gt;
 &lt;br /&gt;
      if(str != &amp;quot;stop&amp;quot;) { &lt;br /&gt;
        str = str + &amp;quot;\r\n&amp;quot;; // add newline &lt;br /&gt;
        try { &lt;br /&gt;
          fstr_out.Write(str); &lt;br /&gt;
        } catch(IOException exc) { &lt;br /&gt;
          Console.WriteLine(exc.Message + &amp;quot;File Error&amp;quot;); &lt;br /&gt;
          return ; &lt;br /&gt;
        } &lt;br /&gt;
      } &lt;br /&gt;
    } while(str != &amp;quot;stop&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    fstr_out.Close(); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Asynchronously reads a stream==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
// Async.cs -- Asynchronously reads a stream&lt;br /&gt;
//&lt;br /&gt;
//             Compile this program with the following command line;&lt;br /&gt;
//                 C:&amp;gt;csc Async.cs&lt;br /&gt;
//&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace nsStreams&lt;br /&gt;
{&lt;br /&gt;
    public class Async&lt;br /&gt;
    {&lt;br /&gt;
        static Byte [] data = new Byte[64];&lt;br /&gt;
        static bool bDone = true;&lt;br /&gt;
        static public void Main (string [] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;Please enter a file name&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            FileStream istrm;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                istrm = new FileStream (args[0], FileMode.Open,&lt;br /&gt;
                                        FileAccess.Read, FileShare.Read,&lt;br /&gt;
                                        data.Length, true);&lt;br /&gt;
            }&lt;br /&gt;
            catch (FileNotFoundException)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (args[0] + &amp;quot; was not found&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;Cannot open &amp;quot; + args[0] +&lt;br /&gt;
                                   &amp;quot; for reading&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            AsyncCallback cb = new AsyncCallback (ShowText);&lt;br /&gt;
            long Length = istrm.Length;&lt;br /&gt;
            int count = 0;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                if (Length == istrm.Position)&lt;br /&gt;
                    break;&lt;br /&gt;
                if (bDone)&lt;br /&gt;
                {&lt;br /&gt;
                    bDone = false;&lt;br /&gt;
                    istrm.BeginRead (data, 0, data.Length, cb, count);&lt;br /&gt;
                    ++count;&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep (250);&lt;br /&gt;
            }&lt;br /&gt;
            istrm.Close ();&lt;br /&gt;
        }&lt;br /&gt;
        static public void ShowText (IAsyncResult result)&lt;br /&gt;
        {&lt;br /&gt;
            for (int x = 0; x &amp;lt; data.Length; ++x)&lt;br /&gt;
            {&lt;br /&gt;
                if (data[x] == 0)&lt;br /&gt;
                    break;&lt;br /&gt;
                Console.Write ((char) data[x]);&lt;br /&gt;
                data[x] = 0;&lt;br /&gt;
            }&lt;br /&gt;
            bDone = true;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Catch file read exception and retry==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class Retry {&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        StreamReader sr;&lt;br /&gt;
        int attempts = 0;&lt;br /&gt;
        int maxAttempts = 3;&lt;br /&gt;
    GetFile:&lt;br /&gt;
        Console.Write(&amp;quot;\n[Attempt #{0}] Specify file &amp;quot; + &amp;quot;to open/read: &amp;quot;, attempts + 1);&lt;br /&gt;
        string fileName = Console.ReadLine();&lt;br /&gt;
        try {&lt;br /&gt;
            sr = new StreamReader(fileName);&lt;br /&gt;
            string s;&lt;br /&gt;
            while (null != (s = sr.ReadLine())) {&lt;br /&gt;
                Console.WriteLine(s);&lt;br /&gt;
            }&lt;br /&gt;
            sr.Close();&lt;br /&gt;
        } catch (FileNotFoundException e) {&lt;br /&gt;
            Console.WriteLine(e.Message);&lt;br /&gt;
            if (++attempts &amp;lt; maxAttempts) {&lt;br /&gt;
                Console.Write(&amp;quot;Do you want to select another file: &amp;quot;);&lt;br /&gt;
                string response = Console.ReadLine();&lt;br /&gt;
                response = response.ToUpper();&lt;br /&gt;
                if (response == &amp;quot;Y&amp;quot;) goto GetFile;&lt;br /&gt;
            } else {&lt;br /&gt;
                Console.Write(&amp;quot;You have exceeded the maximum retry limit ({0})&amp;quot;, maxAttempts);&lt;br /&gt;
            }&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            Console.WriteLine(e.Message);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Construct StreamWriter from FileSream==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
public class IOExample&lt;br /&gt;
{&lt;br /&gt;
  static void Main() {   &lt;br /&gt;
    FileStream fs;&lt;br /&gt;
    StreamWriter sw;&lt;br /&gt;
&lt;br /&gt;
    try {&lt;br /&gt;
      fs = new FileStream(&amp;quot;practice.txt&amp;quot;, FileMode.Open );&lt;br /&gt;
      sw = new StreamWriter(fs);&lt;br /&gt;
      // write a line to the file&lt;br /&gt;
      string newLine = &amp;quot;Not so different from you and me&amp;quot;;&lt;br /&gt;
      sw.WriteLine(newLine);&lt;br /&gt;
      // close the streams&lt;br /&gt;
      sw.Close();&lt;br /&gt;
      fs.Close();&lt;br /&gt;
    } catch (IOException ioe) {&lt;br /&gt;
      Console.WriteLine(&amp;quot;IOException occurred: &amp;quot;+ioe.Message);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create a StreamWriter in UTF8 mode==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Text;&lt;br /&gt;
class MainClass {&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        using (FileStream fs = new FileStream(&amp;quot;test.txt&amp;quot;, FileMode.Create)) {&lt;br /&gt;
            using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) {&lt;br /&gt;
                w.WriteLine(124.23M);&lt;br /&gt;
                w.WriteLine(&amp;quot;Test string&amp;quot;);&lt;br /&gt;
                w.WriteLine(&amp;quot;!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        using (FileStream fs = new FileStream(&amp;quot;test.txt&amp;quot;, FileMode.Open)) {&lt;br /&gt;
            using (StreamReader r = new StreamReader(fs, Encoding.UTF8)) {&lt;br /&gt;
                Console.WriteLine(Decimal.Parse(r.ReadLine()));&lt;br /&gt;
                Console.WriteLine(r.ReadLine());&lt;br /&gt;
                Console.WriteLine(Char.Parse(r.ReadLine()));&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Demonstrates attaching a StreamReader object to a stream==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
// StrmRdr.cs -- Demonstrates attaching a StreamReader object to a stream&lt;br /&gt;
//&lt;br /&gt;
//               Compile this program with the following command line:&lt;br /&gt;
//                   C:&amp;gt;csc StrmRdr.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace nsStreams&lt;br /&gt;
{&lt;br /&gt;
    public class StrmRdr&lt;br /&gt;
    {&lt;br /&gt;
        static public void Main (string [] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;Please enter a file name&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            FileStream strm;&lt;br /&gt;
            StreamReader reader;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                // Create the stream&lt;br /&gt;
                strm = new FileStream (args[0], FileMode.Open, FileAccess.Read);&lt;br /&gt;
                // Link a stream reader to the stream&lt;br /&gt;
                reader = new StreamReader (strm);&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (e.Message);&lt;br /&gt;
                Console.WriteLine (&amp;quot;Cannot open &amp;quot; + args[0]);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            while (reader.Peek() &amp;gt;= 0)&lt;br /&gt;
            {&lt;br /&gt;
                string text = reader.ReadLine ();&lt;br /&gt;
                Console.WriteLine (text);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close ();&lt;br /&gt;
            strm.Close ();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Demonstrates attaching a StreamWriter object to a stream==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
// StrmWrtr.cs -- Demonstrates attaching a StreamWriter object to a stream&lt;br /&gt;
//&lt;br /&gt;
//                Compile this program with the following command line:&lt;br /&gt;
//                    C:&amp;gt;csc StrmWrtr.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace nsStreams&lt;br /&gt;
{&lt;br /&gt;
    public class StrmWrtr&lt;br /&gt;
    {&lt;br /&gt;
        static public void Main (string [] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;Please enter a file name&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            FileStream strm;&lt;br /&gt;
            StreamWriter writer;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
// Create the stream&lt;br /&gt;
                strm = new FileStream (args[0], FileMode.OpenOrCreate, FileAccess.Write);&lt;br /&gt;
// Link a stream reader to the stream&lt;br /&gt;
                writer = new StreamWriter (strm);&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (e.Message);&lt;br /&gt;
                Console.WriteLine (&amp;quot;Cannot open &amp;quot; + args[0]);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            strm.SetLength (0);&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                 string str = Console.ReadLine ();&lt;br /&gt;
                 if (str.Length == 0)&lt;br /&gt;
                     break;&lt;br /&gt;
                 writer.WriteLine (str);&lt;br /&gt;
            }&lt;br /&gt;
            writer.Close ();&lt;br /&gt;
            strm.Close ();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==illustrates reading and writing text data==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
 /*&lt;br /&gt;
  Example15_16.cs illustrates reading and writing text data&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
public class Example15_16 &lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    // create a new file to work with&lt;br /&gt;
    FileStream outStream = File.Create(&amp;quot;c:\\TextTest.txt&amp;quot;);&lt;br /&gt;
    // use a StreamWriter to write data to the file&lt;br /&gt;
    StreamWriter sw = new StreamWriter(outStream);&lt;br /&gt;
    // write some text to the file&lt;br /&gt;
    sw.WriteLine(&amp;quot;This is a test of the StreamWriter class&amp;quot;);&lt;br /&gt;
    // flush and close&lt;br /&gt;
    sw.Flush();&lt;br /&gt;
    sw.Close();&lt;br /&gt;
    // now open the file for reading&lt;br /&gt;
    StreamReader sr = new StreamReader(&amp;quot;c:\\TextTest.txt&amp;quot;);&lt;br /&gt;
    // read the first line of the file into a buffer and display it&lt;br /&gt;
    string FirstLine;&lt;br /&gt;
  &lt;br /&gt;
    FirstLine = sr.ReadLine();&lt;br /&gt;
    Console.WriteLine(FirstLine);&lt;br /&gt;
    // clean up&lt;br /&gt;
    sr.Close();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Open a file using StreamWriter==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Open a file using StreamWriter.  &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
using System.IO; &lt;br /&gt;
  &lt;br /&gt;
public class KtoD1 { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    string str; &lt;br /&gt;
    StreamWriter fstr_out; &lt;br /&gt;
 &lt;br /&gt;
    // Open the file directly using StreamWriter. &lt;br /&gt;
    try { &lt;br /&gt;
      fstr_out = new StreamWriter(&amp;quot;test.txt&amp;quot;); &lt;br /&gt;
    } &lt;br /&gt;
    catch(IOException exc) { &lt;br /&gt;
      Console.WriteLine(exc.Message + &amp;quot;Cannot open file.&amp;quot;); &lt;br /&gt;
      return ; &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Enter text (&amp;quot;stop&amp;quot; to quit).&amp;quot;); &lt;br /&gt;
    do { &lt;br /&gt;
      Console.Write(&amp;quot;: &amp;quot;); &lt;br /&gt;
      str = Console.ReadLine(); &lt;br /&gt;
 &lt;br /&gt;
      if(str != &amp;quot;stop&amp;quot;) { &lt;br /&gt;
        str = str + &amp;quot;\r\n&amp;quot;; // add newline &lt;br /&gt;
        try { &lt;br /&gt;
          fstr_out.Write(str); &lt;br /&gt;
        } catch(IOException exc) { &lt;br /&gt;
          Console.WriteLine(exc.Message + &amp;quot;File Error&amp;quot;); &lt;br /&gt;
          return ; &lt;br /&gt;
        } &lt;br /&gt;
      } &lt;br /&gt;
    } while(str != &amp;quot;stop&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    fstr_out.Close(); &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Read data in line by line==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class Program {&lt;br /&gt;
    static void Main(string[] args) {&lt;br /&gt;
        string strLine;&lt;br /&gt;
        try {&lt;br /&gt;
            FileStream aFile = new FileStream(&amp;quot;Log.txt&amp;quot;, FileMode.Open);&lt;br /&gt;
            StreamReader sr = new StreamReader(aFile);&lt;br /&gt;
            strLine = sr.ReadLine();&lt;br /&gt;
            while (strLine != null) {&lt;br /&gt;
                Console.WriteLine(strLine);&lt;br /&gt;
                strLine = sr.ReadLine();&lt;br /&gt;
            }&lt;br /&gt;
            sr.Close();&lt;br /&gt;
        } catch (IOException e) {&lt;br /&gt;
            Console.WriteLine(&amp;quot;An IO exception has been thrown!&amp;quot;);&lt;br /&gt;
            Console.WriteLine(e.ToString());&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reading from a text file line by line==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass {&lt;br /&gt;
    public static void Main(string[] args) {&lt;br /&gt;
        try {&lt;br /&gt;
            FileStream fs = new FileStream(&amp;quot;c:\\a.txt&amp;quot;, FileMode.Open);&lt;br /&gt;
            StreamReader sr = new StreamReader(fs);&lt;br /&gt;
            string line = &amp;quot;&amp;quot;;&lt;br /&gt;
            int lineNo = 0;&lt;br /&gt;
            do {&lt;br /&gt;
                line = sr.ReadLine();&lt;br /&gt;
                if (line != null) {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;{0}: {1}&amp;quot;, lineNo, line);&lt;br /&gt;
                    lineNo++;&lt;br /&gt;
                }&lt;br /&gt;
            } while (line != null);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            Console.WriteLine(&amp;quot;Exception in ShowFile: {0}&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==StreamReader And Writer==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * C# Programmers Pocket Consultant&lt;br /&gt;
 * Author: Gregory S. MacBeth&lt;br /&gt;
 * Email: gmacbeth@comporium.net&lt;br /&gt;
 * Create Date: June 27, 2003&lt;br /&gt;
 * Last Modified Date:&lt;br /&gt;
 * Version: 1&lt;br /&gt;
 */&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace Client.Chapter_11___File_and_Streams&lt;br /&gt;
{&lt;br /&gt;
  public class StreamReaderAndWriter {&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      StreamReader MyStreamReader = new StreamReader(@&amp;quot;c:\Projects\Testing.txt&amp;quot;);&lt;br /&gt;
      //If you need to control share permissions when creating a file you&lt;br /&gt;
      //use FileStream with StreamReader&lt;br /&gt;
      FileStream MyFileStream = new FileStream(@&amp;quot;c:\Projects\Testing.txt&amp;quot;, FileMode.Open, FileAccess.Read, FileShare.None);&lt;br /&gt;
      StreamReader MyStreamReader2 = new StreamReader(MyFileStream);&lt;br /&gt;
      MyFileStream.Close();&lt;br /&gt;
      MyStreamReader2.Close();&lt;br /&gt;
      //The easiest way to Read a stream is to use the ReadLine method.&lt;br /&gt;
      //This method reads until it gets to the end of a line, but ...&lt;br /&gt;
      //it does not copy the carriage return line feed /n/r.&lt;br /&gt;
      string MyStringReader = MyStreamReader.ReadLine();&lt;br /&gt;
      //You can also read the whole file by using the following&lt;br /&gt;
      string MyStringReadToEOF = MyStreamReader.ReadToEnd();&lt;br /&gt;
      //The other route is to read one character at a time&lt;br /&gt;
      int[] MyArrayOfCharacters = new int[100];&lt;br /&gt;
      for (int i = 0; i &amp;lt; 99; i++)&lt;br /&gt;
      {&lt;br /&gt;
        MyArrayOfCharacters[i] = MyStreamReader.Read();&lt;br /&gt;
      }&lt;br /&gt;
      MyStreamReader.Close();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==StreamReader.ReadLine==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        FileStream fs2 = File.Create(&amp;quot;Bar.txt&amp;quot;);&lt;br /&gt;
        StreamWriter w2 = new StreamWriter(fs2);&lt;br /&gt;
        w2.Write(&amp;quot;Goodbye Mars&amp;quot;);&lt;br /&gt;
        w2.Close();&lt;br /&gt;
        fs2 = File.Open(&amp;quot;Bar.txt&amp;quot;, FileMode.Open, FileAccess.Read, FileShare.None);&lt;br /&gt;
        StreamReader r2 = new StreamReader(fs2);&lt;br /&gt;
        String t;&lt;br /&gt;
        while ((t = r2.ReadLine()) != null) {&lt;br /&gt;
            Console.WriteLine(t);&lt;br /&gt;
        }&lt;br /&gt;
        w2.Close();&lt;br /&gt;
        fs2.Close();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The use of a buffered stream to serve as intermediate data holder for another stream==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
// BufStrm.cs -- demonstates the use of a buffered stream to serve&lt;br /&gt;
//               as intermediate data holder for another stream.&lt;br /&gt;
//&lt;br /&gt;
//                Compile this program with the following command line:&lt;br /&gt;
//                    C:&amp;gt;csc BufStrm.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace nsStreams&lt;br /&gt;
{&lt;br /&gt;
    public class BufStrm&lt;br /&gt;
    {&lt;br /&gt;
        static public void Main ()&lt;br /&gt;
        {&lt;br /&gt;
            FileStream strm;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                strm = new FileStream (&amp;quot;./BufStrm.txt&amp;quot;,&lt;br /&gt;
                                       FileMode.OpenOrCreate,&lt;br /&gt;
                                       FileAccess.Write);&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (e.Message);&lt;br /&gt;
                Console.WriteLine (&amp;quot;Cannot open ./BufStrm.txt&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            strm.SetLength (0);&lt;br /&gt;
            BufferedStream bstrm = new BufferedStream (strm);&lt;br /&gt;
            string str = &amp;quot;Now is the time for all good men to &amp;quot; +&lt;br /&gt;
                         &amp;quot;come to the aid of their Teletype.\r\n&amp;quot;;&lt;br /&gt;
            byte [] b;&lt;br /&gt;
            StringToByte (out b, str);&lt;br /&gt;
            bstrm.Write (b, 0, b.Length);&lt;br /&gt;
// Save the current position to fix an error.&lt;br /&gt;
            long Pos = bstrm.Position;&lt;br /&gt;
            Console.WriteLine (&amp;quot;The buffered stream position is &amp;quot;&lt;br /&gt;
                               + bstrm.Position);&lt;br /&gt;
            Console.WriteLine (&amp;quot;The underlying stream position is &amp;quot;&lt;br /&gt;
                               + strm.Position);&lt;br /&gt;
            str = &amp;quot;the quick red fox jumps over the lazy brown dog.\r\n&amp;quot;;&lt;br /&gt;
            StringToByte (out b, str);&lt;br /&gt;
            bstrm.Write (b, 0, b.Length);&lt;br /&gt;
            Console.WriteLine (&amp;quot;\r\nThe buffered stream position is &amp;quot; +&lt;br /&gt;
                               bstrm.Position);&lt;br /&gt;
            Console.WriteLine (&amp;quot;The underlying stream position is still &amp;quot;&lt;br /&gt;
                               + strm.Position);&lt;br /&gt;
// Fix the lower case letter at the beginning of the second string&lt;br /&gt;
            bstrm.Seek (Pos, SeekOrigin.Begin);&lt;br /&gt;
            b[0] = (byte) &amp;quot;T&amp;quot;;&lt;br /&gt;
            bstrm.Write (b, 0, 1);&lt;br /&gt;
// Flush the buffered stream. This will force the data into the&lt;br /&gt;
// underlying stream.&lt;br /&gt;
            bstrm.Flush ();&lt;br /&gt;
            bstrm.Close ();&lt;br /&gt;
            strm.Close ();&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
// Convert a buffer of type string to byte&lt;br /&gt;
        static void StringToByte (out byte [] b, string str)&lt;br /&gt;
        {&lt;br /&gt;
            b = new byte [str.Length];&lt;br /&gt;
            for (int x = 0; x &amp;lt; str.Length; ++x)&lt;br /&gt;
            {&lt;br /&gt;
                b[x] = (byte) str [x];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//File: BufStrm.txt&lt;br /&gt;
/*&lt;br /&gt;
Now is the time for all good men to come to the aid of their Teletype.&lt;br /&gt;
The quick red fox jumps over the lazy brown dog.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Try and catch exceptions for StreamWriter==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * C# Programmers Pocket Consultant&lt;br /&gt;
 * Author: Gregory S. MacBeth&lt;br /&gt;
 * Email: gmacbeth@comporium.net&lt;br /&gt;
 * Create Date: June 27, 2003&lt;br /&gt;
 * Last Modified Date:&lt;br /&gt;
 */&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace Client.Chapter_9___Exceptions_and_AppDomains&lt;br /&gt;
{&lt;br /&gt;
  public class MyMainClassChapter_9___Exceptions_and_AppDomains&lt;br /&gt;
  {&lt;br /&gt;
    delegate int MyDelegate(string s);&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      StreamWriter MyStream = null;&lt;br /&gt;
      string MyString = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
        MyStream = File.CreateText(&amp;quot;MyFile.txt&amp;quot;);&lt;br /&gt;
        MyStream.Write(MyString);&lt;br /&gt;
      }&lt;br /&gt;
      catch (IOException e)&lt;br /&gt;
      {&lt;br /&gt;
        Console.WriteLine(e);&lt;br /&gt;
      }&lt;br /&gt;
      catch (Exception e)&lt;br /&gt;
      {&lt;br /&gt;
        Console.WriteLine(e);&lt;br /&gt;
      }&lt;br /&gt;
      finally&lt;br /&gt;
      {&lt;br /&gt;
        if (MyStream != null)&lt;br /&gt;
          MyStream.Close();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public class MyFile&lt;br /&gt;
  {&lt;br /&gt;
    public StreamWriter WriteText(string s)&lt;br /&gt;
    {&lt;br /&gt;
      if (!Valid(s))&lt;br /&gt;
        throw new IOException(&amp;quot;Can&amp;quot;t Write String&amp;quot;);&lt;br /&gt;
      else&lt;br /&gt;
        return new StreamWriter(&amp;quot;c:\\test.txt&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public bool Valid(string s)&lt;br /&gt;
    {&lt;br /&gt;
      return false;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use StreamWriter to create a text file==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
&lt;br /&gt;
public class MyStreamWriterReader {&lt;br /&gt;
    static void Main(string[] args) {&lt;br /&gt;
        StreamWriter writer = new StreamWriter(&amp;quot;reminders.txt&amp;quot;);&lt;br /&gt;
        writer.WriteLine(&amp;quot;...&amp;quot;);&lt;br /&gt;
        writer.WriteLine(&amp;quot;Don&amp;quot;t forget these numbers:&amp;quot;);&lt;br /&gt;
        for (int i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
            writer.Write(i + &amp;quot; &amp;quot;);&lt;br /&gt;
        writer.Write(writer.NewLine);&lt;br /&gt;
        writer.Close();&lt;br /&gt;
        StreamReader sr = new StreamReader(&amp;quot;reminders.txt&amp;quot;);&lt;br /&gt;
        string input = null;&lt;br /&gt;
        while ((input = sr.ReadLine()) != null) {&lt;br /&gt;
            Console.WriteLine(input);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using StreamWriter 3==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * C# Programmers Pocket Consultant&lt;br /&gt;
 * Author: Gregory S. MacBeth&lt;br /&gt;
 * Email: gmacbeth@comporium.net&lt;br /&gt;
 * Create Date: June 27, 2003&lt;br /&gt;
 * Last Modified Date:&lt;br /&gt;
 * Version: 1&lt;br /&gt;
 */&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace Client.Chapter_11___File_and_Streams&lt;br /&gt;
{&lt;br /&gt;
  public class UsingStreamWriter {&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      //StreamWriter can only be use to write to files or other streams&lt;br /&gt;
      StreamWriter MyStreamWriter = new StreamWriter(@&amp;quot;c:\Projects\Testing.txt&amp;quot;);&lt;br /&gt;
      //You can also use FileStream with StreamWriter to provide a greater degree of control&lt;br /&gt;
      //in how you open the file&lt;br /&gt;
      FileStream MyFileStream = new FileStream(@&amp;quot;c:\Projects\Testing.txt&amp;quot;, FileMode.CreateNew, FileAccess.Write, FileShare.None);&lt;br /&gt;
      StreamWriter MyStreamWriter2 = new StreamWriter(MyFileStream);&lt;br /&gt;
      MyFileStream.Close();&lt;br /&gt;
      MyStreamWriter2.Close();&lt;br /&gt;
      //You can write sequentially to a file using this technique&lt;br /&gt;
      FileInfo MyFile = new FileInfo(@&amp;quot;c:\Projects\Testing.txt&amp;quot;);&lt;br /&gt;
      StreamWriter MyStreamWriter3 = MyFile.CreateText();&lt;br /&gt;
      MyStreamWriter3.Close();&lt;br /&gt;
      //There are four overloaded ways to use StreamWriter.Write()&lt;br /&gt;
      //Writes a stream to a file&lt;br /&gt;
      string MyString = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
      MyStreamWriter.Write(MyString);&lt;br /&gt;
      //Writes single characters to a stream&lt;br /&gt;
      char MyChar = &amp;quot;A&amp;quot;;&lt;br /&gt;
      MyStreamWriter.Write(MyChar);&lt;br /&gt;
      //Writes an Array of characters&lt;br /&gt;
      char[] MyCharArray = new char[100];&lt;br /&gt;
      for (int i = 0; i &amp;lt; 99; i++)&lt;br /&gt;
      {&lt;br /&gt;
        MyCharArray[i] = (char)i;&lt;br /&gt;
      }&lt;br /&gt;
      MyStreamWriter.Write(MyCharArray);&lt;br /&gt;
      //or you can write a portion of an array&lt;br /&gt;
      MyStreamWriter.Write(MyCharArray, 25, 30);&lt;br /&gt;
      MyStreamWriter.Close();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>