StreamReader.ReadToEnd() ফাইলের পুরো কন্টেন্ট একসাথে স্ট্রিং হিসেবে পড়ে। using ব্লক ব্যবহার করে অটোমেটিক ডিসপোজ নিশ্চিত করুন।
উদাহরণ
using System;
using System.IO;
public class Demo {
public static void Main() {
// ফাইল লিখি
using (StreamWriter sw = new StreamWriter("new.txt")) {
sw.WriteLine("One");
sw.WriteLine("Two");
}
// ফাইল পড়ি
using (StreamReader sr = new StreamReader("new.txt")) {
string content = sr.ReadToEnd();
Console.WriteLine(content);
}
}
}
আউটপুট
One Two