using System;
using System.IO;
class MainClass
{
    static void Main()
    {
        // StreamReader型の変数を定義
        StreamReader sample = null;
        try
        {
            // ファイルを開く
            sample = new StreamReader
                ("Sample.txt", System.Text.Encoding.Default);
            // ファイルの内容を読み込む
            string text = sample.ReadToEnd();
            Console.Write(text);
        }
        catch (Exception error)
        {
            // 例外の内容の詳細情報を表示
            Console.WriteLine(error.Message);
        }
        finally
        {
            if (sample != null)
            {
                // ファイルを閉じる
                sample.Close();
            }
        }
    }
}
						
0 コメント:
コメントを投稿