8.16 - Convert a text file to uppercase

Objetive

Write a program to read a text file and dump its content to another file, changing the lowercase letters to uppercase.

You must deliver only the ".cs" file, with you name in a comment.


Solution

using System;
using System.IO;

namespace FileLowerCaseToUpperCase
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter name file: ");
            string fileName = Console.ReadLine();

            if (File.Exists(fileName))
            {
                StreamReader fileRw = File.OpenText(fileName);
                StreamWriter fileWr = File.CreateText(fileName + ".dat");
                string line;
                do
                {
                    line = fileRw.ReadLine();
                    if (line != null)
                        fileWr.WriteLine(line.ToUpper());
                }
                while (line != null);
                fileRw.Close();
                fileWr.Close();
            }
        }
    }
}


Popular Posts