streamwriter

kasirajankasirajan TamilNadu,india
edited April 2014 in C#
class Program
    {
        static void Main(string[] args)
        {``
            string[] names = new string[] { "kasi", "rajan" };
            using (StreamWriter sw = new StreamWriter(@"C:\Users\kasi\Desktop\jamica.txt")) 
            {
                foreach (string s in names)
                {
                    Console.WriteLine(s);
                }
            }
           string line = "";
            using (StreamReader sr = new StreamReader(@"C:\Users\kasi\Desktop\jamica.txt"))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    Console.ReadLine();
                }
            }
            Console.ReadLine();
        }
    }

Comments

  • kasirajankasirajan TamilNadu,india

    why its not writing in file?

  • Because you are writing to the Console instead of the Stream. Line 10 should be sw.WriteLine();

  • mazanujmazanuj Ukraine, Kiev

    if you to write all array in file use System.IO.File.WriteAllLines(array)

    if you want to read all text from file use string t = System.IO.File.ReadAllText(fileName)

    or read file in array string[] t = System.IO.File.ReadAllLines(fileName)

  • kasirajankasirajan TamilNadu,india

    i got it thnx..

  • mazanujmazanuj Ukraine, Kiev

    @kasirajan said:
    i got it thnx..

    >
    mark comment as answer or write your

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories