VB.NET读取TXT文件数据保存为数组
比如txt上有如下数据217,194,26204,177,36203,185,83148,157,100第一行存为数组1,第二行存为数组2······方便调用里面数据。希...
比如txt上有如下数据
217,194,26
204,177,36
203,185,83
148,157,100
第一行存为数组1,第二行存为数组2······方便调用里面数据。希望高人指点 展开
217,194,26
204,177,36
203,185,83
148,157,100
第一行存为数组1,第二行存为数组2······方便调用里面数据。希望高人指点 展开
推荐于2016-11-12 · 知道合伙人互联网行家
关注
展开全部
VB.NET编程读取txt文本文档中的数据,并把数据保存为数组,代码如下:
'写配件文件
Private Sub saveIni(ByVal filePath As String, ByVal str As String)
Dim sw As StreamWriter = New StreamWriter(filePath, True) 'true是指以追加的方式打开指定文件
sw.WriteLine(str)
sw.Flush()
sw.Close()
sw = Nothing
End Sub
'读配件文件
Private Function readIni(ByVal filePath As String)
Dim iniDt As New DataTable
iniDt.Columns.Add("text")
iniDt.Columns.Add("value")
Try
Dim sr As StreamReader = New StreamReader(filePath, System.Text.Encoding.Default)
Dim line As String = ""
While Not sr.EndOfStream
Dim str = sr.ReadLine()'读取当前行
iniDt.Rows.Add(New String() {
str(0),
str(1)
})
End While
sr.Close()
sr = Nothing
Catch ex As Exception
End Try
Return iniDt
End Function
展开全部
Dim txt As IO.StreamReader = New IO.StreamReader("C:\1.txt", System.Text.Encoding.Default)
Dim str() As String, n As Integer = 0
Do Until txt.EndOfStream
n = n + 1
ReDim Preserve str(n) '数组从1开始
str(n) = txt.ReadLine()
Loop
txt.Close()
Dim str() As String, n As Integer = 0
Do Until txt.EndOfStream
n = n + 1
ReDim Preserve str(n) '数组从1开始
str(n) = txt.ReadLine()
Loop
txt.Close()
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询