File Operations, c ++ File Operations
Txt operation
Write
using (FileStream fs = new FileStream("test.txt", FileMode.Append, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.Default)) { sw.WriteLine("I Love You"); } }
Read
using (FileStream fs = new FileStream("test.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (StreamReader sr = new StreamReader(fs, Encoding.Default)) { textBox1.Text = sr.ReadToEnd(); } }
Array Storage:String [] lines = File. ReadAllLines (file, Encoding. Default );
File (folder) operation: Directory (similar)
File. copy (@ "E: \ file.txt", @ "F: \ file.txt", false); File. create (@ "F: \ kk.txt"); // Create a file on drive F. You can set security permissions and other information in the overload. File. Exists (@ "E: \ file.txt"); // True if the File Exists; otherwise, False
Delete the entire folder and all files
Directory. Delete (path, true );