streamreader()的使用
霜与寒雪 2006-03-30 09:12:35 我用下面这段代码:使用时报出输入的字符格式不正确,请大虾帮我看看问题出在哪个地方的?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strPath As String
Dim myfilestream As FileStream
Dim mystreamreader As StreamReader
Dim intread As Integer = 0
Dim readchr() As Char
Dim strread As String = ""
Try
OpenFileDialog1.ShowDialog()
strPath = OpenFileDialog1.FileName
' MsgBox(strPath)
myfilestream = New FileStream(strPath, FileMode.Open, FileAccess.Read)
mystreamreader = New StreamReader(myfilestream)
intread = mystreamreader.BaseStream.Length
ReDim readchr(intread)
intread = mystreamreader.Read(readchr, 0, intread)
strread = Convert.ToSingle(readchr)
txt.Text = strread
myfilestream.Close()
mystreamreader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub