একটি ফাইলের সমস্ত লাইন একবারে পড়ার জন্য ReadAllText() পদ্ধতি ব্যবহার করুন৷
ধরা যাক নিচের লাইনগুলি সহ আমাদের কাছে একটি ফাইল “hello.txt” আছে −
One Two Three
উপরের ফাইলটি পড়তে, প্যারামিটার হিসাবে ফাইলের পাথ যোগ করুন।
File.ReadAllText(myPath);
উপরে, myPath-এর ফাইল পাথ ছিল।
String myPath = "hello.txt";
আসুন সম্পূর্ণ কোডটি দেখি -
উদাহরণ
using System; using System.IO; public class Demo { public static void Main() { String myPath = "hello.txt"; String allLines; allLines = File.ReadAllText(myPath); Console.WriteLine(allLines); } }
আউটপুট
নিচের আউটপুট −
One Two Three