← Tutti gli articoli

Read from a text file and write in a text file

20 settembre 2010  · C# · Article  ·  34 visite

Read from a text file and write in a text file

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // create a writer and open the file

            TextReader tr = new StreamReader("e:\\deleghe.txt");

            TextWriter tw = new StreamWriter("e:\\deleghe2.txt");
            //System.IO.File file;
            StreamReader sr = new StreamReader("e:\\deleghe.txt");
            // write a line of text to the file
            string riga;

            while (sr.Peek() != -1)
            {
                riga = sr.ReadLine();
                if (riga.Substring(0, 1) != "1")
                {
                    tw.WriteLine(riga);
                }
            }

            

            // close the stream
            tw.Close();

        }
    }
}