读取文本文件,然后将所有行添加到 VB.NET 中的列表框中 [英] Read a text file and then add all lines to list box in VB.NET
本文介绍了读取文本文件,然后将所有行添加到 VB.NET 中的列表框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的桌面上有一个文本文件...
I have a text file in my desktop...
在这个文件中,我们有五行:
In this file we have five lines:
Line 1
Line 2
Line 3
Line 4
Line 5
如果用户选择此文本文件,则所有行(五行)都添加到列表框项中.
If the user choose this text file then all lines (five lines) add to list box items.
例如,我们在列表框中有这些(当用户选择文本文件(它有五行)时):
For example, we have these in the list box (when the user choose the text file (which it has five lines)):
Line 1
Line 2
Line 3
Line 4
Line 5
推荐答案
试试这个:
Dim lines() As String = IO.File.ReadAllLines("C:\dir\file.txt")
ListBox1.Items.AddRange(lines)
这篇关于读取文本文件,然后将所有行添加到 VB.NET 中的列表框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文