FileSystem.OpenTextFileWriter Método
Definição
Abre um objeto StreamWriter no qual o arquivo especificado será gravado.Opens a StreamWriter object to write to the specified file.
Sobrecargas
| OpenTextFileWriter(String, Boolean) |
Abre um objeto StreamWriter no qual o arquivo especificado será gravado.Opens a StreamWriter object to write to the specified file. |
| OpenTextFileWriter(String, Boolean, Encoding) |
Abre um StreamWriter para gravar no arquivo especificado.Opens a StreamWriter to write to the specified file. |
OpenTextFileWriter(String, Boolean)
Abre um objeto StreamWriter no qual o arquivo especificado será gravado.Opens a StreamWriter object to write to the specified file.
public:
static System::IO::StreamWriter ^ OpenTextFileWriter(System::String ^ file, bool append);
public static System.IO.StreamWriter OpenTextFileWriter (string file, bool append);
static member OpenTextFileWriter : string * bool -> System.IO.StreamWriter
Public Shared Function OpenTextFileWriter (file As String, append As Boolean) As StreamWriter
Parâmetros
- file
- String
Arquivos que serão gravados.File to be written to.
- append
- Boolean
True para acrescentar ao conteúdo do arquivo; False para substituir o conteúdo do arquivo.True to append to the contents of the file; False to overwrite the contents of the file. O padrão é False.Default is False.
Retornos
Objeto StreamWriter no qual o arquivo especificado será gravado.StreamWriter object to write to the specified file.
Exceções
file é Nothing ou é uma cadeia de caracteres vazia.file is Nothing or an empty string.
O nome do arquivo termina com uma barra.The file name ends with a trailing slash.
Exemplos
Este exemplo abre um StreamWriter com o My.Computer.FileSystem.OpenTextFileWriter método e o usa para gravar uma cadeia de caracteres em um arquivo de texto com o WriteLine método da StreamWriter classe.This example opens a StreamWriter with the My.Computer.FileSystem.OpenTextFileWriter method and uses it to write a string to a text file with the WriteLine method of the StreamWriter class.
Dim file = My.Computer.FileSystem.OpenTextFileWriter(
"c:\test.txt", True)
file.WriteLine("Here is the first string.")
file.Close()
Comentários
O OpenTextFileWriter método abre e inicializa um fluxo para um arquivo e, em seguida, retorna o StreamWriter objeto para esse fluxo.The OpenTextFileWriter method opens and initializes a stream for a file and then returns the StreamWriter object for that stream. Você pode gravar no fluxo quantas vezes forem necessárias e fechá-lo quando terminar.You can write to the steam as many times as necessary and then close it when you are finished.
Observação
Você deve chamar o Close método no StreamWriter objeto para garantir que todos os dados sejam gravados corretamente no fluxo subjacente.You must call the Close method on the StreamWriter object to make sure that all data is correctly written to the underlying stream.
Se você estiver gravando apenas algumas cadeias de caracteres em um arquivo, pode ser mais simples usar o WriteAllText método.If you are writing only a few strings to a file, it might be simpler to use the WriteAllText method.
A tabela a seguir lista um exemplo de uma tarefa que envolve o My.Computer.FileSystem.OpenTextFileWriter método.The following table lists an example of a task involving the My.Computer.FileSystem.OpenTextFileWriter method.
| ParaTo | ConsulteSee |
|---|---|
Gravar texto em um arquivo com um StreamWriterWrite text to a file with a StreamWriter |
Como gravar texto em arquivos com um StreamWriter no Visual BasicHow to: Write Text to Files with a StreamWriter in Visual Basic |
Confira também
Aplica-se a
OpenTextFileWriter(String, Boolean, Encoding)
Abre um StreamWriter para gravar no arquivo especificado.Opens a StreamWriter to write to the specified file.
public:
static System::IO::StreamWriter ^ OpenTextFileWriter(System::String ^ file, bool append, System::Text::Encoding ^ encoding);
public static System.IO.StreamWriter OpenTextFileWriter (string file, bool append, System.Text.Encoding encoding);
static member OpenTextFileWriter : string * bool * System.Text.Encoding -> System.IO.StreamWriter
Public Shared Function OpenTextFileWriter (file As String, append As Boolean, encoding As Encoding) As StreamWriter
Parâmetros
- file
- String
Arquivos que serão gravados.File to be written to.
- append
- Boolean
True para acrescentar ao conteúdo do arquivo; False para substituir o conteúdo do arquivo.True to append to the contents in the file; False to overwrite the contents of the file. O padrão é False.Default is False.
- encoding
- Encoding
Codificação a ser usada na gravação no arquivo.Encoding to be used in writing to the file. O padrão é ASCII.Default is ASCII.
Retornos
Objeto StreamWriter no qual o arquivo especificado será gravado.StreamWriter object to write to the specified file.
Exceções
file é Nothing ou é uma cadeia de caracteres vazia.file is Nothing or an empty string.
O nome do arquivo termina com uma barra.The file name ends with a trailing slash.
Exemplos
Este exemplo abre um StreamWriter com o My.Computer.FileSystem.OpenTextFileWriter método com Unicode codificação e o usa para gravar uma cadeia de caracteres em um arquivo de texto com o WriteLine método da StreamWriter classe.This example opens a StreamWriter with the My.Computer.FileSystem.OpenTextFileWriter method with Unicode encoding and uses it to write a string to a text file with the WriteLine method of the StreamWriter class.
Dim file = My.Computer.FileSystem.OpenTextFileWriter(
"c:\test.txt", True, Text.Encoding.Unicode)
file.WriteLine("Here is the first string.")
file.Close()
Comentários
O OpenTextFileWriter método abre e inicializa um fluxo para um arquivo e, em seguida, retorna o StreamWriter objeto para esse fluxo.The OpenTextFileWriter method opens and initializes a stream for a file and then returns the StreamWriter object for that stream. Você pode gravar no fluxo quantas vezes forem necessárias e fechá-lo quando terminar.You can write to the steam as many times as necessary and then close it when you are finished.
Observação
Você deve chamar o Close método no StreamWriter objeto para garantir que todos os dados sejam gravados corretamente no fluxo subjacente.You must call the Close method on the StreamWriter object to make sure that all data is correctly written to the underlying stream.
Se você estiver gravando apenas algumas cadeias de caracteres em um arquivo, pode ser mais simples usar o WriteAllText método.If you are writing only a few strings to a file, it might be simpler to use the WriteAllText method.
A tabela a seguir lista um exemplo de uma tarefa que envolve o My.Computer.FileSystem.OpenTextFileWriter método.The following table lists an example of a task involving the My.Computer.FileSystem.OpenTextFileWriter method.
| ParaTo | ConsulteSee |
|---|---|
Gravar texto em um arquivo com um StreamWriterWrite text to a file with a StreamWriter |
Como gravar texto em arquivos com um StreamWriter no Visual BasicHow to: Write Text to Files with a StreamWriter in Visual Basic |