0% found this document useful (0 votes)
6 views1 page

C# File Read Write Example

Uploaded by

Manasa M R
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

C# File Read Write Example

Uploaded by

Manasa M R
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

C# Program to Write to and Read from a Text File

Below is a sample C# program that writes text to a file and reads it back:

using System;
using [Link];

namespace FileReadWriteDemo
{
class Program
{
static void Main(string[] args)
{
string filePath = "[Link]"; // File name

// Writing to the file


string textToWrite = "Hello, this is a sample text written to the file!";
[Link](filePath, textToWrite);
[Link]("Text successfully written to the file.");

// Reading from the file


string readText = [Link](filePath);
[Link]("Content read from the file:");
[Link](readText);

[Link]("\nPress any key to exit...");


[Link]();
}
}
}

You might also like