|
-
Dec 5th, 2003, 04:36 AM
#1
Thread Starter
Member
FileIO in .NET?
Hi. In dos based c++,i've done something like reading/writing a structure to a file. Is this possible with VB.NET? I've would like to save an object(probably a class) or even multiple object to a file and retrieve it's binary data and cast it back to an object.
For eg. if i have a class:
Public Class Student
Public Name As String
Public Age As Integer
Public DateOfBirth As Date
Public Religion As ReligionConstant
End Class
And I have few objects of the Student:
Dim Matty As New Student()
Dim Steven As New Student()
Dim Jay As New Student()
Matty.Name = "Matty"
Matty.Age = 12
Matty.DateOfBirth = "#12/5/2003#"
Matty.Religion = ReligionConstant.Christian
Steven.Name = "Steven"
Steven.Age = 21
Steven.DateOfBirth = "#12/5/2003#"
Steven.Religion = ReligionConstant.Christian
Jay.Name = "Jay"
Jay.Age = 35
Jay.DateOfBirth = "#9/9/2003#"
Jay.Religion = ReligionConstant.Christian
I would like to save these information into a file using binary format (not text) and need to know how to read these info and cast it back to an object. Thanks in advance.
Archaven
-
Dec 5th, 2003, 06:46 AM
#2
Banned
to read and write the binary data the example is
import system.io
dim fs as filestream = new filestream("data.dat",filemode.open)
dim mybinaryreader as binaryreader = new binaryreader(fs)
dim buffer(1000) as byte
mybinaryreader.rad(buffer,0,1000)
Like this .if u can say i write the full program.but i think it give u idea.
Biswajit das
-
Dec 5th, 2003, 09:17 AM
#3
Check out "Serialization" in the help index. That tells you how to write class data to either binary or XML files.
-
Dec 5th, 2003, 09:48 AM
#4
Yeah Serialize is great for taking collections and arrays and saving them out to file
I have a C# example here
http://www.planet-source-code.com/vb...=186&lngWId=10
Since you said you know C++, you shouldnt have any problem with the above code since C# is baically the same as VB.NET using C style syntax.
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
|