From Visual Studio Help:
Basic File I/O
The abstract base class Stream supports reading and writing bytes. Stream integrates asynchronous support. Its default implementations define synchronous reads and writes in terms of their corresponding asynchronous methods, and vice versa.
All classes that represent streams inherit from the Stream class. The Stream class and its derived classes provide a generic view of data sources and repositories, isolating the programmer from the specific details of the operating system and underlying devices.
Streams involve these fundamental operations:
⢠Streams can be read from. Reading is the transfer of
data from a stream into a data structure, such as an
array of bytes.
⢠Streams can be written to. Writing is the transfer of
data from a data source into a stream.
⢠Streams can support seeking. Seeking is the querying and
modifying of the current position within a stream.
Depending on the underlying data source or repository, streams might support only some of these capabilities. For example, NetworkStreams do not support seeking. The CanRead, CanWrite, and CanSeek properties of Stream and its derived classes determine the operations that various streams support.
Classes Used for File I/O
FileObject provides a representation of a text file. Use the FileObject class to perform most typical text file operations such as reading, writing, appending, copying, deleting, moving, or renaming. You can also use FileObject to examine and, in some cases, set file attributes, encoding, and path information.
Directory provides static methods for creating, moving, and enumerating through directories and subdirectories. The DirectoryInfo class provides instance methods.
DirectoryInfo provides instance methods for creating, moving, and enumerating through directories and subdirectories. The Directory class provides static methods.
File provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of a FileStream. The FileInfo class provides instance methods.
FileInfo provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of a FileStream. The File class provides static methods.
FileStream supports random access to files through its Seek method. FileStream opens files synchronously by default, but supports asynchronous operation as well. File contains static methods, and FileInfo contains instance methods.
FileSystemInfo is the abstract base class for FileInfo and DirectoryInfo.
Path provides methods and properties for processing directory strings in a cross-platform manner.
File, FileInfo, Path, Directory, and DirectoryInfo are sealed (in Microsoft
VB, NotInheritable) classes. You can create new instances of these classes, but they cannot have derived classes.
Classes Used for Reading from and Writing to Streams
BinaryReader and BinaryWriter read and write encoded strings and primitive data types from and to Streams.
StreamReader reads characters from Streams, using Encoding to convert characters to and from bytes. StreamReader has a constructor that attempts to ascertain what the correct Encoding for a given Stream is, based on the presence of an Encoding-specific preamble, such as a byte order mark.
StreamWriter writes characters to Streams, using Encoding to convert characters to bytes.
StringReader reads characters from Strings. StringReader allows you to treat Strings with the same API, so your output can be either a Stream in any encoding or a String.
StringWriter writes characters to Strings. StringWriter allows you to treat Strings with the same API, so your output can be either a Stream in any encoding or a String.
TextReader is the abstract base class for StreamReader and StringReader. While the implementations of the abstract Stream class are designed for byte input and output, the implementations of TextReader are designed for Unicode character output.
TextWriter is the abstract base class for StreamWriter and StringWriter. While the implementations of the abstract Stream class are designed for byte input and output, the implementations of TextWriter are designed for Unicode character input.
================================================== ====================
In Visual Studio Help:
Writing Text to a File
The following code example shows a simple way to write text to a text file:
Code:
Imports System
Imports System.IO
Class Test
Public Shared Sub Main()
' Create an instance of StreamWriter to write text to a file.
Dim sw As StreamWriter = New StreamWriter("TestFile.txt")
' Add some text to the file.
sw.Write("This is the ")
sw.WriteLine("header for the file.")
sw.WriteLine("-------------------")
' Arbitrary objects can also be written to the file.
sw.Write("The date is: ")
sw.WriteLine(DateTime.Now)
sw.Close()
End Sub
End Class
The following code example creates a new text file and writes a string to it:
Code:
Option Explicit On
Option Strict On
Imports System
Imports System.IO
Public Class TextToFile
Private Const FILE_NAME As String = "MyFile.txt"
Public Shared Sub Main()
If File.Exists(FILE_NAME) Then
Console.WriteLine("{0} already exists.", FILE_NAME)
Return
End If
Dim sr As StreamWriter = File.CreateText(FILE_NAME)
sr.WriteLine("This is my file.")
' {0} and {1} (those are curly braces) in the fol. are replaceable
' parameters. The arguments â1â and â4.2â will automatically be
' put in their place. Those arguments can be variables, func-
' tions, recordset values, etc.
sr.WriteLine("I can write ints {0} or floats {1}, and so on.", 1, 4.2)
sr.Close()
End Sub
End Class
Does this get you there?