📄 class1.cs
字号:
using System;
using System.IO;
public class Class1
{
public static void Main()
{
// create a reference to a file, which may or may not exist
// if it doesn't exist, it is not yet created
FileInfo fi = new FileInfo("temp.txt");
// create a writer, ready to add entries to the file
StreamWriter sw = fi.AppendText();
sw.WriteLine("Add as many lines as you like...");
sw.WriteLine("Add another line to the output...");
sw.Flush();
sw.Close();
// get the information out of the file, and print it to screen
StreamReader sr = new StreamReader( fi.OpenRead() );
Console.WriteLine("This is the information in the first file:");
while (sr.Peek() != -1)
Console.WriteLine( sr.ReadLine() );
// copy this file to ANOTHER file. The true parameter indicates
// to overwrite the file if it already exists
FileInfo newfi = fi.CopyTo("newTemp.txt", true);
// get the information out of the new file, and print it to screen
sr = new StreamReader( newfi.OpenRead() );
Console.WriteLine("{0}This is the information in the second file:", Environment.NewLine);
while (sr.Peek() != -1)
Console.WriteLine( sr.ReadLine() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -