|
هذه المقالة مترجمة يدويًا. حرك المؤشر فوق الجمل في المقالة لعرض النص الأصلي. المزيد من المعلومات.
|
الترجمة
الأصلي
|
كيفية القيام بما يلي: القراءة من ملف نصي (دليل البرمجة لـ #C)
Visual Studio 2010
ملاحظة
|
|---|
|
|
class ReadFromFile { static void Main() { // The files used here were created in the code example // in How to: Write to a Text File. You can of course substitute // other files of your own. // Example #1 // Read the file as one string. string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteText.txt"); // Display the file contents to the console. System.Console.WriteLine("Contents of writeText.txt = {0}", text); // Example #2 // Read the file lines into a string array. string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines2.txt"); System.Console.WriteLine("Contents of writeLines2.txt =:"); foreach (string line in lines) { Console.WriteLine("\t" + line); } // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); } }
ملاحظة