Imports System.IO
模块模块1
Structure student
Dim studentname As String
Dim rollnumber As String
Dim studentclass As String
End Structure
'Structure writing
' End Structure
' Structure reading
'End Structure
Sub Main()
Dim newstudent As student
newstudent.studentname = "DDD"
newstudent.rollnumber = "123"
newstudent.studentclass = "AS"
Dim studentstream As New FileStream("C:\Users\___\Desktop\A2Filing.dat", FileMode.OpenOrCreate)
Dim bw As New BinaryWriter(studentstream)
studentstream.Position = 33
bw.Write(newstudent.studentname)
bw.Write(newstudent.rollnumber)
bw.Write(newstudent.studentclass)
bw.Close()
studentstream.Close()
Dim br As New BinaryReader(studentstream)
studentstream.Position = 11
newstudent.studentname = br.ReadString
newstudent.rollnumber = br.ReadString
newstudent.studentclass = br.ReadString
Console.WriteLine(newstudent.studentname)
Console.WriteLine(newstudent.rollnumber)
Console.WriteLine(newstudent.studentclass)
br.Close()
Console.ReadKey()
End Sub
问题是它不允许我声明二进制阅读器错误仍然是
流不可读
即使我尝试使用不同的变量声明一个新的文件流,我也尝试将读取和写入放在不同的结构中,它给了我这个:
结构中的非共享成员不能声明为“新”
(当我尝试声明“新”文件流“)
数组边界不能出现在类型说明符
中
(当我尝试给它文件位置时)
预期声明
(当我尝试声明二进制编写器时,它表示即使声明了上面只有2行,也没有声明studentstream)