Behaves like the Linux cat utility - CSharp File IO

CSharp examples for File IO:Text File

Description

Behaves like the Linux cat utility

Demo Code


using System;//from w w w .j  a v  a  2  s .com
using System.IO;

public class cat
{
    public static void Main(string[] args)
    {
        String line;
        foreach(string filename in args)
        {
            StreamReader file;

            if (File.Exists(filename))
            {
                file = new StreamReader(@filename);

                while((line = file.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                }

                file.Close();
            }
            else
            {
                Console.WriteLine("Oops, file {0} not found!", filename);
            }

            Console.WriteLine();
        }
    }
}

Related Tutorials