

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to read all the lines of a file at once
Use ReadAllText() method to read all the lines of a file at once.
Let’s say we have a file “hello.txt” with the following lines −
One Two Three
To read the above file, add the path of the file as parameter.
File.ReadAllText(myPath);
Above, myPath had the file path.
String myPath = "hello.txt";
Let us see the complete code −
Example
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); } }
Output
The following is the output −
One Two Three
- Related Questions & Answers
- C# Program to read contents of a file into a string at once
- C# Program to read all the lines one by one in a file
- Saving all the open Matplotlib figures in one file at once
- Golang Program to Read the Contents of a File
- C# Program to count the number of lines in a file
- C Program to count the number of lines in a file?
- How to close all activities at once in android?
- How to download all images on a web page at once?
- How to close all Android activities at once using Kotlin?
- Write a Python program to read an Excel data from file and read all rows of first and last columns
- How to set all the values at once using the model in a JProgressBar with Java?
- How to set all the four border radius properties at once with JavaScript?
- C program to count characters, lines and number of words in a file
- C++ program to read file word by word?
- How to read the contents of a JSON file using Java?
Advertisements