C# IO.File


The file class is used to create, delete, copy, move, and open files

Member function explain example
File.Create() Create a file File.Create(@”D:\temp.txt”);
File.Copy() Copy file File.Copy (@ “source path”, @ “target path”);
File.Delete() Delete file
File.Exists() If the file exists, put it back into bool
File.Move() move file
File.Replace() Replacing a file will delete the source file, but it can be backed up File.Replace (source file, replacement file, backup)

get attribute

Member function explain example
File.GetCreationTime() Get creation time
File.GetLastAccessTime() Get last visit time
File.GetLastWriteTime() Get last write time

Reading and writing

Member function explain example
File.WriteAllText() Write text
File.WriteAllLine() Write rows as array, wrapping each line
File.WriteAllBytes() Write data in byte array
File.ReadAllText() Read in text
File.ReadAllLines() Read rows as arrays, wrapping each row. Return string []
File.ReadAllBytes() Read in data according to byte array. Return byte []
File.AppendText() Additional content

File.AppendText Additional content

using (StreamWriter sw = File.AppendText(@"D:\temp.txt")) {
    sw.WriteLine (the "additional text");