Facilitates writing to a standard text file.
Accessing files and directories is done under the context of the user that the application or service is running under. This can cause some file permissions/access rights issues if the file does not allow access to that user.
Constructors
none
Instance Properties
none
Static Methods
WriteAllText
Creates a new file, writes the specified string to the file. If the target file already exists, it is overwritten.
Syntax:Parameters:path: The file to append the specified string to.
contents: The string to append to the file.
Example:
s = "Joe\r\nMike\r\nSandy\r\n";
TextFileWriter.WriteAllText("c:\myfiles\names.txt", s);
AppendAllText
Appends the specified string to the file, creating the file if it does not already exist
Syntax:Parameters:path: The file to append the specified string to.
contents: The string to append to the file.
Example:
s = "Tammy";
TextFileWriter.AppendAllText("c:\myfiles\names.txt", s);
CreateText
Creates or opens a file for writing UTF-8 encoded text.
Syntax:Parameters:path: The file to be opened for writing.
Return ValueExample:
file = TextFileWriter.CreateText("c:\myfiles\names.txt");
Instance Methods
Write( String )
Writes the string to the file.
Syntax:Parametersvalue: The value to write to the file.
Example:
file = TextFileWriter.CreateText("c:\myfiles\names.txt");
file.Write("Joe\r\nMike\r\nSandy\r\n");
file.Close();
Write( Number )
Writes the number to the file.
Syntax:Parametersvalue: The value to write to the file.
Example:
file = TextFileWriter.CreateText("c:\myfiles\myfile.txt");
n = 12;
file.Write(n);
file.Close();
Write( Boolean )
Writes the text representation of a boolean to the file.
Syntax:Parametersvalue: The value to write to the file.
Example:
file = TextFileWriter.CreateText("c:\myfiles\myfile.txt");
b = false;
file.Write( b );
file.Close();
WriteLine( String )
Writes the text representation of a boolean followed by a line terminator to the file.
Syntax:Parametersvalue: The value to write to the file.
Example:
file = TextFileWriter.CreateText("c:\myfiles\names.txt");
file.WriteLine("Joe");
file.WriteLine("Mike");
file.WriteLine("Sandy");
file.Close();
WriteLine( Number )
Writes a number followed by a line terminator to the file.
Syntax:Parametersvalue: The value to write to the file.
Example:
file = TextFileWriter.CreateText("c:\myfiles\myfile.txt");
n = 12;
file.WriteLine(n);
file.Close();
WriteLine( Boolean )
Writes the text representation of a boolean followed by a line terminator to the file.
Syntax:Parametersvalue: The value to write to the file.
Example:
file = TextFileWriter.CreateText("c:\myfiles\myfile.txt");
b = false;
file.WriteLine( b );
file.Close();
Close
Closes the current file.
Syntax:Example:
file = TextFileWriter.OpenText("c:\myfiles\names.txt");
s = file.Peek();
file.Close();
See Also