长沙婚纱摄影工作室:VB.net 读取文件
来源:百度文库 编辑:查人人中国名人网 时间:2024/05/10 06:12:59
有人给我这样一段代码,但是总是提示streamreader未定义,请高手指导一下,StreamReader如何定义?谢谢了!!
Imports System
Imports System.IO
Imports System.Collections
Module Module1
Sub Main()
Dim objReader As New StreamReader("c:\test.txt")
Dim sLine As String = ""
Dim arrText As New ArrayList()
Do
sLine = objReader.ReadLine()
If Not sLine Is Nothing Then
arrText.Add(sLine)
End If
Loop Until sLine Is Nothing
objReader.Close()
For Each sLine In arrText
Console.WriteLine(sLine)
Next
Console.ReadLine()
End Sub
End Module
Imports System
Imports System.IO
Imports System.Collections
Module Module1
Sub Main()
Dim objReader As New StreamReader("c:\test.txt")
Dim sLine As String = ""
Dim arrText As New ArrayList()
Do
sLine = objReader.ReadLine()
If Not sLine Is Nothing Then
arrText.Add(sLine)
End If
Loop Until sLine Is Nothing
objReader.Close()
For Each sLine In arrText
Console.WriteLine(sLine)
Next
Console.ReadLine()
End Sub
End Module
1、你的计算机上是否真的有c:\test.txt文件,你看一下;
2、可以把 Dim objReader As New StreamReader("c:\test.txt") 换成:
Using objReader As StreamReader = File.OpenText("C:\Test.txt")