Read and Write a Text File : Text File Read Write : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » Text File Read Write »

 

Read and Write a Text File








    
 

using System;
using System.IO;
using System.Text;

public class TextFileTest {

    private static void Main() {
        FileStream fs = new FileStream("test.txt", FileMode.Create);

        StreamWriter w = new StreamWriter(fs, Encoding.UTF8);

        w.WriteLine(1.2M);
        w.WriteLine("string");
        w.WriteLine('!');
        w.Flush();
        w.Close();
        fs.Close();

        fs = new FileStream("test.txt", FileMode.Open);
        StreamReader r = new StreamReader(fs, Encoding.UTF8);

        Console.WriteLine(Decimal.Parse(r.ReadLine()));
        Console.WriteLine(r.ReadLine());
        Console.WriteLine(Char.Parse(r.ReadLine()));

        r.Close();
        fs.Close();
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» Text File Read Write