Writing a file to disk
-
I was wondering how you would write a file to disk. In 6.0 you used the open command. I was just wanted to know the process of writing to disk.
What kind of file were you looking at writing? There are a few methods available. Text files are the easiest and can be done using the FileStream classes:
Dim sr As StreamWriter = File.CreateText(FILE\_NAME) sr.WriteLine("This is my file.") sr.Close()
Binary files are a little more complicated but are still be based on FileStream classes:
Dim fs As New FileStream(FILE\_NAME, FileMode.CreateNew) ' Create the writer for data. Dim w As New BinaryWriter(fs)
' Write data.
Dim i As Integer
For i = 0 To 10
w.Write(CInt(i))
Next i
w.Close()
fs.Close()
' Create the reader for data.
fs = New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)
Dim r As New BinaryReader(fs)
' Read data from Test.data.
For i = 0 To 10
Console.WriteLine(r.ReadInt32())
Next i
w.Close()For more information, lookup 'FileStream Class' in the VS Help Index, or on MSDN here[^]. RageInTheMachine9532