网站首页 > 文章中心 > 其它

vb.net流读取文件

作者:小编 更新时间:2023-09-05 07:50:45 浏览量:125人看过

vb.net读取文件流

dim filename as string = "文件名" Using myfilestream As New FileStream(FileName, FileMode.Open, FileAccess.Read)

Dim data() As Byte

ReDim data(myfilestream.Length - 1)

myfilestream.Read(data, 0, myfilestream.Length)

myfilestream.Close()

' data是你要的结果,为byte(), End Using

vb.net中,读取和写入文件

写入:Dim sr As New IO.StreamWriter(Application.StartupPath "/写入的文本.txt")

sr.WriteLine("写入的内容") sr.Close()读取:If (File.Exists(Application.StartupPath "/msg.txt")) Then

Dim fm As New IO.FileStream(Application.StartupPath "/读取的文本.txt", FileMode.Open)

Dim sr As IO.StreamReader = New IO.StreamReader(fm)

Do While sr.Peek() = 0

TextBox1.Text = sr.ReadLine() (读取文本到文本框)

Loop end if

VB.net 读取文本文件

Imports?System.IO

Public?Class?Form1

Private?Sub?Form1_Load(sender?As?System.Object,?e?As?System.EventArgs)?Handles?MyBase.Load

Dim?sr?As?New?StreamReader("d:\test.csv")

Do?Until?sr.EndOfStream

Dim?str?As?String?=?sr.ReadLine

Dim?s()?As?String?=?str.Split(",")

ListBox1.Items.Add(s(0))

Loop

arr1?=?CType(a1.ToArray(GetType(Integer)),?Integer())

sr.Close()

End?Sub

End?Class

VB.net 读取文本文件?

①.、实现上传按钮方法代码.

VB.net窗体设计中,如何读取.txt文件中的数据?

Private Sub Command1_Click()

Dim strFile? ? ?As String

Dim intFile? ? ?As Integer

Dim strData? ? ?As String

strFile = "c:\学生成绩.txt"

intFile = FreeFile

Open strFile For Input As intFile

strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)

Debug.Print strData

Close intFile

End Sub

vb.net 怎样读取文件

imports System.IO

读取指定文件

'

'读取指定文本文件

Public Function readtext(ByVal path As String)

If path = "" Then

readtext = "操作失败!"

Exit Function

End If

Try

If File.Exists(path) = True Then

Dim fs As New FileStream(path, FileMode.Open)

Dim sr As New StreamReader(fs)

Dim str As String

str = sr.ReadToEnd.ToString

fs.Close()

readtext = str

Else

Catch ex As Exception

End Try

End Function

'向指定文件写入数据

Public Function writetext(ByVal path As String, ByVal opi As Integer, ByVal msg As String)

writetext = "操作失败!"

Dim op As FileMode

Select Case opi

Case 1

op = FileMode.Append

op = FileMode.Create

Case Else

End Select

Dim fs As New FileStream(path, op)

Dim sr As New StreamWriter(fs)

sr.WriteLine(msg)

writetext = "操作完成!"

以上就是土嘎嘎小编为大家整理的vb.net流读取文件相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章