copyfileupper.cs

来自「csharp-solution,C#高效编程源码」· CS 代码 · 共 50 行

CS
50
字号
    using System;
	using System.IO;

    /// <summary>
    ///    Class to create an upper case copy of a file
    /// </summary>
    public class CopyFileUpper
    {
		public static void Main()
		{
			string sFrom;
			string sTo;
			StreamReader srFrom;
			StreamWriter swTo;

			// Prompt for the input filename
			Console.Write("Copy From: ");
			sFrom = Console.ReadLine();

			// Prompt for the output filename
			Console.Write("Copy To: ");
			sTo = Console.ReadLine();

			try 
			{
				srFrom = new StreamReader(sFrom);
				swTo = new StreamWriter(sTo);

				while (srFrom.Peek() != -1)
				{
					string sBuffer = srFrom.ReadLine();
					sBuffer = sBuffer.ToUpper();
					swTo.WriteLine(sBuffer);
				}
		
				srFrom.Close();
				swTo.Close();
			} 
			catch (FileNotFoundException)
			{
				Console.WriteLine("Input file not found");
			}
			catch (Exception e)
			{
				Console.WriteLine("Unexpected exception");
				Console.WriteLine(e.ToString());
			}
		}       
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?