|
-
Nov 20th, 2001, 09:45 PM
#19
Text File I/O
I had a hard time finding information on I/O to text files. I use text files quite a bit at work.
In VB6 you could create a text file like this and output to it like this:
Open "c:\text.txt" for output as #1
Dim TempString as String
TempString = "Write a line to the file"
Print #1, TempString
Close #1
And you could read a text file like this:
Open "c:\text.txt" for input as #1
Dim TempString as String
Line Input #1, Tempstring
Msgbox TempString
Close #1
In VB.net you can create a file like this:
Dim fFileStream as FileStream = New FileStream("c:\text.txt", File.Create)
fFileStream.Close
Write to a text file like this:
Dim fStreamWriter as StreamWriter = New StreamWriter("c:\test.txt")
fStreamWriter.Writeline("This line is being written in the file")
fStreamWriter.Close()
And Read a line from a text file like this:
Dim FStreamReader as StreamReader = New StreamReader("c:\test.txt")
msgbox(fStreamReader.Readline())
fStreamReader.Close()
Always be sure to use the close method when you are done with using a file!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|