|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
File.WriteAllLines Método (String, String[], Encoding)
Assembly: mscorlib (em mscorlib. dll)
public static void WriteAllLines( string path, string[] contents, Encoding encoding )
Parâmetros
- path
- Tipo: System.String
O arquivo para gravar.
- contents
- Tipo: System.String[]
A matriz de Cadeia de Caracteres para gravar o arquivo.
- encoding
- Tipo: System.Text.Encoding
An Encoding object that represents the character encoding applied to the string array.
| Exceção | Condição |
|---|---|
| ArgumentException | |
| ArgumentNullException | |
| PathTooLongException | |
| DirectoryNotFoundException | |
| IOException | |
| UnauthorizedAccessException | |
| FileNotFoundException | |
| NotSupportedException | |
| SecurityException |
using System; using System.IO; using System.Text; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. string[] createText = { "Hello", "And", "Welcome" }; File.WriteAllLines(path, createText, Encoding.UTF8); } // This text is always added, making the file longer over time // if it is not deleted. string appendText = "This is extra text" + Environment.NewLine; File.AppendAllText(path, appendText, Encoding.UTF8); // Open the file to read from. string[] readText = File.ReadAllLines(path, Encoding.UTF8); foreach (string s in readText) { Console.WriteLine(s); } } }
- FileIOPermission
Para acessar gravar um arquivo ou diretório. Enumeração associada: FileIOPermissionAccess.Write.