কম্পিউটার টিউটোরিয়াল

C#-এ প্লেইন টেক্সট ফাইল খোলা

একটি প্লেইন টেক্সট ফাইল খোলতে StreamReader ক্লাস ব্যবহার করুন। নিচের কোডটি একটি ফাইল পড়ার জন্য খোলে:

StreamReader sr = new StreamReader("d:/new.txt")

এখন ফাইলের কন্টেন্ট প্রদর্শন করুন:

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

সম্পূর্ণ উদাহরণ

using System;
using System.IO;

namespace FileApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (StreamReader sr = new StreamReader("d:/new.txt"))
                {
                    string line;
                    // ফাইল থেকে লাইন পড়ুন এবং প্রদর্শন করুন
                    // ফাইল শেষ পর্যন্ত
                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }
                }
            }
            catch (Exception e)
            {
                // ব্যবহারকারীকে জানান কী ভুল হয়েছে
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
    }
}

আউটপুট

The file could not be read: Could not find a part of the path "d:/new.txt".
  1. ম্যাকওএসে টেক্সট ফাইল তৈরি করার ধাপে ধাপে গাইড

  2. Windows 10-এ .pages ফাইল খোলার সহজ পদ্ধতি: ধাপে ধাপে গাইড

  3. উইন্ডোজ 10-এ GZ ফাইল খোলা: সহজ ধাপ এবং নির্ভরযোগ্য টুলসমূহ

  4. .DAT ফাইল কী? কীভাবে খোলা এবং ব্যাখ্যা করবেন