如何读取txt文件的数据?

kathy_ni 2005-09-22 05:10:33
如何读取txt文件中的数据?比如文件名为a.txt,能不能给个简单的例子?
...全文
197 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
singlepine 2005-09-22
  • 打赏
  • 举报
回复
Imports System
Imports System.IO
Imports System.Text

Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
Dim fs As FileStream

' Delete the file if it exists.
If File.Exists(path) = False Then
' Create the file.
fs = File.Create(path)
Dim info As Byte() = _
New UTF8Encoding(True).GetBytes("This is some text in the file.")

' Add some information to the file.
fs.Write(info, 0, info.Length)
fs.Close()
End If

' Open the stream and read it back.
Dim sr As StreamReader = File.OpenText(path)

Do While sr.Peek() >= 0
Console.WriteLine(sr.ReadLine())
Loop

sr.Close()
End Sub
End Class
kathy_ni 2005-09-22
  • 打赏
  • 举报
回复
如果要一行一行的读?怎么个读法?
wuyq11 2005-09-22
  • 打赏
  • 举报
回复
Dim Write As StreamWriter
Dim Path As String = Application.StartupPath
Write.WriteLine(temp)
Write = New StreamWriter(Path + "\ConnStr.txt")
AreZong 2005-09-22
  • 打赏
  • 举报
回复
读取文本文件,写入列表框中:

Dim input As TextReader = File.OpenText("MyFile.txt")
Dim line As String
line = input.ReadLine()
While Not (line Is Nothing)
ListBox1.Items.Add(line)
line = input.ReadLine()
End While
input.Close()
lionelwy 2005-09-22
  • 打赏
  • 举报
回复
using Systme.IO;


StreamReader sr = new StreamReader("a.txt");
string text = sr.readEnd();
sr.close();

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧