今日得分最低问题:FileStream的运用

2066 2003-12-30 08:33:30
以下是代码,请解释
Module Module1

Sub Main()
Dim FS As IO.FileStream
Dim FReader As IO.StreamReader
Dim FWriter As IO.StreamWriter
Dim LineContex As String = "a"
FS = New IO.FileStream("H:\test.txt", IO.FileMode.Create, IO.FileAccess.Write)
FWriter = New IO.StreamWriter(FS)
Console.WriteLine("输入文件内容:")
While LineContex.Length > 0
LineContex = Console.ReadLine
FWriter.WriteLine(LineContex)
End While
FWriter.Close()
FS = New IO.FileStream("H:\test.txt", IO.FileMode.Open, IO.FileAccess.Read)
FReader = New IO.StreamReader(FS)
LineContex = FReader.ReadToEnd()
Console.WriteLine(LineContex)
FS.Seek(0, IO.SeekOrigin.Begin)
While FReader.Peek > -1
LineContex = FReader.ReadLine
Console.WriteLine(LineContex)
End While
FReader.Close()
Console.Read()
End Sub

End Module
...全文
25 2 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
8620 2004-01-10
up
  • 打赏
  • 举报
回复
2066 2003-12-30
Module Module1

Sub Main()
Dim TextLine As String = ""
Dim Flag As Boolean = True
Dim Fs As IO.FileStream
Dim Sr As IO.StreamReader
Dim Sw As IO.StreamWriter
Fs = New IO.FileStream("h:\test.txt", IO.FileMode.Create, IO.FileAccess.Write)
Sw = New IO.StreamWriter(Fs)
Dim iCount As Integer
While Flag
TextLine = InputBox("请输入一行文字,这行文字将保存到文件中")
If TextLine = "" Then
Flag = False
Else
Sw.WriteLine(TextLine)
End If
End While
Sw.Close()
Fs = New IO.FileStream("h:\test.txt", IO.FileMode.Open, IO.FileAccess.Read)
Sr = New IO.StreamReader(Fs)
Flag = True
While Flag
If Sr.Peek = -1 Then '如果文件读取完毕,peek 返因值为-1
Flag = False
Else
TextLine = Sr.ReadLine()
Console.WriteLine(TextLine)
End If
End While
Sr.Close()
MsgBox("Ok")
End Sub

End Module
  • 打赏
  • 举报
回复
相关推荐
发帖
VB
加入

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
申请成为版主
帖子事件
创建了帖子
2003-12-30 08:33
社区公告
暂无公告