streamwriter - Programmers Heaven

Howdy, Stranger!

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

Categories

streamwriter

kasirajankasirajan TamilNadu,indiaPosts: 6Member
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();
        }
    }
Tagged:

Comments

  • kasirajankasirajan TamilNadu,indiaPosts: 6Member

    why its not writing in file?

  • mk44mk44 UKPosts: 9Member

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

  • mazanujmazanuj Ukraine, KievPosts: 18Member

    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,indiaPosts: 6Member

    i got it thnx..

  • mazanujmazanuj Ukraine, KievPosts: 18Member

    @kasirajan said:
    i got it thnx..

    >
    mark comment as answer or write your

Sign In or Register to comment.