ফাইলের সকল লাইন একসাথে পড়তে 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