The first time you run:
Second run time:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.IO;
Namespace file operations
{
Class Program
{
static void Main (string[] args)
{
To create a text file, it's best to judge
StreamWriter SW;
if (! File.exists ("Templog.txt"))
{
Create a new text file if it does not exist, and write some content
SW = File.createtext ("Templog.txt");
Sw. Write ("First word");
Sw. WriteLine ("Follow the boss's.");
Sw. WriteLine ("Current date is:");
Sw. WriteLine (DateTime.Now);
}
Else
{
Add some text content if it exists
SW = File.appendtext ("Templog.txt");
for (int i = 0; i < i++)
{
Sw. WriteLine ("can output {0}" as usual to the screen, I);
}
}
Sw. Close ();
Create a Reader
StreamReader sr = new StreamReader ("Templog.txt");
Read at a one-time
Console.WriteLine (Sr. ReadToEnd ());
Console.ReadLine ();
}
}
}