File and Stream IO
suggest changeSyntax
new System.IO.StreamWriter(string path)new System.IO.StreamWriter(string path, bool append)System.IO.StreamWriter.WriteLine(string text)System.IO.StreamWriter.WriteAsync(string text)System.IO.Stream.Close()System.IO.File.ReadAllText(string path)System.IO.File.ReadAllLines(string path)System.IO.File.ReadLines(string path)System.IO.File.WriteAllText(string path, string text)System.IO.File.WriteAllLines(string path, IEnumerable<string> contents)System.IO.File.Copy(string source, string dest)System.IO.File.Create(string path)System.IO.File.Delete(string path)System.IO.File.Move(string source, string dest)System.IO.Directory.GetFiles(string path)
Parameters
| Parameter | Details |
|---|---|
| path | The location of the file. |
| append | If the file exists, true adds data at the end and false overwrites the file. If the file does not exist, it is created either way. |
| text | Text to be written or stored. |
| contents | A collection of strings to be written. |
| source | The location of the file you want to use. |
| dest | The location you want a file to go to. |
Remarks
- Close
Streamobjects when you are done. Ausingblock does this, or you can callmyStream.Close(). - Make sure the current user has the necessary permissions on the path where you are creating the file.
- Verbatim strings should be used when declaring a path string that includes backslashes, like so:
@"C:\MyFolder\MyFile.txt"
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents