File.ReadAllText क्या है
File.ReadAllText एक file खोलता है, अंदर का सारा text पढ़ता है, और इसे एक ही बार में वापस दे देता है, जैसे एक ही झटके में पूरी चिट्ठी पढ़ना। यह किसी छोटी file पढ़ने का सबसे तेज़ तरीका है।
In this page:
Syntax
string content = File.ReadAllText(path);
File.WriteAllText(path, content);
File.ReadAllText
File.ReadAllText एक पूरी file को एक call में एक single string में पढ़ता है, जो छोटी-से-मध्यम text files load करने का सबसे सरल तरीका है। File.WriteAllText लिखने के लिए इसका counterpart है।
दोनों System.IO.File class पर static methods हैं और file को अपने आप खोलते, उपयोग करते, और बंद करते हैं।
Note:
बहुत बड़ी files के लिए,
StreamReader को प्राथमिकता दें ताकि आप file को एक साथ memory में load करने के बजाय line by line process कर सकें।उदाहरण: File.ReadAllText
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string path = "greeting.txt";
File.WriteAllText(path, "Hello from File.WriteAllText!");
string content = File.ReadAllText(path);
Console.WriteLine(content);
}
}
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
File.ReadAllTextसे एक विशाल file पढ़ना, जो इसे पूरी memory में load कर देता है।- गलत relative path उपयोग करना, जिससे
FileNotFoundExceptionफेंका जाता है। IOExceptionयाUnauthorizedAccessExceptionhandle करना भूल जाना।
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: