Create your free e-mail address on Net-C, a European, full and secure mail system: antispam, automatic sorting, webmail, mobile app, PGP encryption. A widely used programming language. The symbol for carbon. Also c The symbol for the Roman numeral one hundred. C The symbol for the speed of light in a vacuum. The symbol for capacitance. The symbol for charge conjugation. Cell phone number 2. Sports center 4. Centigrade 5. Physics charm 6. Now on C-SPAN 1 Jody Olsen Discusses Peace Corps' Mission. Peace Corps Director Jody Olsen talks about the organization’s mission and operations at the Center for Strategic and International.
In C# file operations, normally streams are used to read and write to files. A stream is an additional layer created between an application and a file. The stream is used to ensure smooth read and write operations to the file.
Streams are normally used when reading data from large files. By using streams, the data from large files in broken down into small chunks and sent to the stream. These chunks of data can then be read from the application.
The reason for breaking it down into small chunks is because of the performance impact of reading a big file in one shot. If you were to read the data from say, a 100 MB file at one shot, your application could just hang and become unstable. Best free pc cleaner. The best approach is then to use streams to break the file down into manageable chunks.
So when a write operation is carried out on file, the data to be written, is first written to the stream. From the stream, the data is then written to the file. The same goes for the read operation. In the read operation, data is first transferred from the file to the stream. The data is then read from the application via the stream. Let's look at an example of how we can read and write using streams.
In this tutorial, you will learn-
The stream reader is used to read data from a file using streams. The data from the file is first read into the stream. Thereafter the application reads the data from the stream.
For our example, we will assume that we have a file in the D drive called Example.txt. The file will be a simple text file and have 2 lines as shown below
For our example, we will create a simple Console application and work with File streams
Let's look at an example of how we can use streams for reading data from a file. Enter the below code in the program.cs file.
Code Explanation:-
When the above code is set, and the project is run using Visual Studio, you will get the below output.
Output:-
From the output, you can see that the Stream Reader read both the lines from the file. Finally, the lines of the string read from the stream were sent to the Console.
The stream writer is used to write data to a file using streams. The data from the application is first written into the stream. After that the stream writes the data to the file. Let's look at an example of how we can use streams for writing data from a file. Enter the below code in the program.cs file.
Code Explanation:-
When the above code is set, and the project is run using Visual Studio, you will get the below output.
Output:-
From the output, you can see that the line 'Guru99 – ASP.Net' was added to the file successfully. All the 3 lines of text can be seen in the console.
Summary