Visual Basic.NET(将文本文件导入数组)

类别:.NET开发 点击:0 评论:0 推荐:

开始时引用
Imports System.IO

按钮的Click事件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '打开目标文件(文件流)
        Dim myFs As New FileStream(Application.StartupPath & "\a.txt", FileMode.Open, FileAccess.Read)
        '读文件
        Dim r As New StreamReader(myFs)
        Dim i As Integer
        Dim myLine, tempStr As String
        '创建数组,接收文件数据
        Dim myLineStr(), a(100), b(100) As String
        Dim c(100) As Integer
        i = 0
        myLine = r.ReadLine
        Do While Not (myLine Is Nothing)
            myLineStr = myLine.Split(",")
            a(i) = myLineStr(0)
            b(i) = myLineStr(1)
            c(i) = myLineStr(2)
            i += 1
        Loop
    End Sub

本文地址:http://com.8s8s.com/it/it43707.htm