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