Sunday, 20 May 2018

Stream Writer and Stream Reader in C# File READ WIRTE OPERATIONS





-------------------------------------------------------------------------------------------------------------
FileStream Writer : Code
------------------------------------------------------------------------------------------------------------


 FileStream f = new FileStream(@"C:\Users\salman\Desktop\FILE\streamwriter.txt", FileMode.Open);

            StreamReader r = new StreamReader(f);

            string msg = r.ReadLine();

            Console.ForegroundColor = System.ConsoleColor.Red;



            Console.WriteLine("-------------------------------------------");

         

            Console.ForegroundColor = System.ConsoleColor.Green;





            Console.WriteLine(msg);



            Console.ForegroundColor = System.ConsoleColor.Red;



            Console.WriteLine("-------------------------------------------");

            f.Close();

         

            Console.ReadLine();

-------------------------------------------------------------------------------------------------------------
FileStream Reader : Code
------------------------------------------------------------------------------------------------------------

FileStream f = new FileStream(@"C:\Users\salman\Desktop\FILE\streamwriter.txt", FileMode.Create);
            StreamWriter s = new StreamWriter(f);
            Console.WriteLine("Enter your text: ");
            string msg = Console.ReadLine();

            s.Write(msg);
            s.Close();
            f.Close();
            Console.WriteLine("File created successfully.............");
            Console.ReadLine();



No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...