Article ID: 302309 - Last Review: August 28, 2007 - Revision: 2.5 How to read a text file by using System.IO in Visual Basic 2005 or in Visual Basic .NETThis article was previously published under Q302309
For a Microsoft Visual C# .NET version of this article, see 306777
(http://support.microsoft.com/kb/306777/
)
.
For a Microsoft Visual Basic 6.0 version of this article, see 183638
(http://support.microsoft.com/kb/183638/
)
.
On This PageSUMMARY This article demonstrates how to retrieve information from
a text file and use an ArrayList class to display that information to the user. Reading text files in Visual Basic 2005 or in Visual Basic .NETOpening and reading files for read access is an important part of input/output (IO) functionality, even if you do not need to write to the file in question. This example opens a file for reading, which is useful for text files but is inappropriate for binary files. This example uses one of many methods that are available for opening the file. Although many data structures are available to store information that is retrieved from the file, an ArrayList class is the easiest structure to use. To open and read from the file, this example uses objects from the System.IO namespace, specifically the System.IO.StreamReader class.Note This sample requires some form of a text (.txt) file from which to read. To load and read a text file from Microsoft Visual Basic 2005 or from Microsoft Visual Basic .NET, follow these steps:
Complete code listingPitfallsThere are several things to be aware of when you work with file I/O, including the following items:
REFERENCES For more general information about Visual Basic .NET, see the
following Usenet newsgroup: microsoft.public.dotnet.languages.vb
(http://msdn.microsoft.com/newsgroups/default.aspx?query=VB.NET&dg=&cat=en-us-msdn&lang=en&cr=US&pt=&catlist=774F24A2-F71F-425F-AC2B-DC48AB0DA5C9&dglist=&ptlist=&exp=&sloc=en-us)
| Article Translations
|
Back to the top
