Friday, 11 October 2013

How to Append a file in C#.Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace file
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "my_text.txt";
           

            if (!File.Exists(path))
            {

                StreamWriter sw = new StreamWriter(path);

                sw.WriteLine("hello");

                sw.Close();
            }
            else
            {

                StreamWriter swr = new StreamWriter(path, true);
                swr.WriteLine("heheehheehe");
                swr.WriteLine("lallalaalal");
                swr.Close();

             }
         }
      }


            }

0 comments:

Post a Comment