फ़ाइल की सभी पंक्तियों को एक साथ पढ़ने के लिए 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