vbnet读取文件内容|怎样用vbnet读取本地txt文件

vbnet读取文件内容|怎样用vbnet读取本地txt文件的第1张示图

A. vb.net文件读取txt

读取每行TXT如下代码:

VB.NETcodePublicSubReadFileSample()'打开程序当前路径下的config.txt文件'内容就是楼主贴出来的DimreaderAsTextReader=File.OpenText("config.txt")DimlineAsString=reader.ReadLine()'读第一行line=reader.ReadLine()'读第二行line=reader.ReadLine()'读第三行DimnAsInteger=3'当前行号Whileline<>""Andn<50line=reader.ReadLine()'读下一行n=n+1EndWhileDimitemsAsString()=line.Split("".ToCharArray(),StringSplitOptions.RemoveEmptyEntries)ForEachitemAsStringInitemsConsole.WriteLine(item)NextEndSub

B. vb.net怎么实现读取指定word文档中的内容

添加spire.doc.dll为引用,在vb.net中读取指定word文档的内容到txt文件,代码示例如下:

'加载Word文档

Dim doc As Document = New Documentdocument.LoadFromFile("测试文档.docx")

'使用GetText方法获取文档中的所有文本

Dim s As String = doc.GetText

File.WriteAllText("文本1.txt", s.ToString)

C. 怎样用vb.net读取本地.txt文件

imports System.IO 读取指定文件''读取指定文本文件Public Function readtext(ByVal path As String)If path = "" Thenreadtext = "操作失败!"Exit FunctionEnd IfTryIf File.Exists(path) = True ThenDim fs As New FileStream(path, FileMode.Open)Dim sr As New StreamReader(fs)Dim str As Stringstr = sr.ReadToEnd.ToStringsr.Close()fs.Close()readtext = strElsereadtext = "操作失败!"End IfCatch ex As Exceptionreadtext = "操作失败!"End TryEnd Function'向指定文件写入数据Public Function writetext(ByVal path As String, ByVal opi As Integer, ByVal msg As String)If path = "" Thenwritetext = "操作失败!"Exit FunctionEnd IfDim op As FileModeSelect Case opiCase 1op = FileMode.AppendCase 2op = FileMode.CreateCase Elseop = FileMode.CreateEnd SelectTryIf File.Exists(path) = True ThenDim fs As New FileStream(path, op)Dim sr As New StreamWriter(fs)sr.WriteLine(msg)sr.Close()fs.Close()writetext = "操作完成!"Elsewritetext = "操作失败!"End IfCatch ex As Exceptionwritetext = "操作失败!"End TryEnd Function参考这个吧''vb.net源代码来自www.c-pet.com'

D. vb.net 读取txt文件内容 字符串类型

刚刚试了一下你的代码,你用的 p += pass.ReadLine + vbCrLf,P是Password.txt里所有的字符串连起来,每行加个换行符,相当于原来那个文本文档里的所有内容,如果 p = pass.ReadLine + vbCrLf 就是循环逐行读取,比较两个字符串是否想等可以用 String.Equals(字符串1,字符串2)

E. 使用vb.net读取文件夹中所有文件的指定内容

先按行读出所有数据,然后找到需要的信息

IEnumerable<string>list=File.ReadLines("test.txt",Encoding.Default);foreach(stringsinlist){if(s.Contains("图名")){textBox1.Text+=s+"";}if(s.Contains("图号")){textBox1.Text+=s+"";}}

不好意思,用的C#,其实差不多了,自己改改就好了

F. 如何用vb.net编写读取txt内容的代码

窗体上添加2个文本框,设置成多行,2个按钮,在文本框1里随便输入若干文字,可以多行,单击按钮1,保存到文件。然后单击按钮2,把刚才写入的文件读到文本框2里。代码如下:'写文本文件Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click'创建(写入)一个文本文件Dim MyStream As New System.IO.FileStream(Application.StartupPath & "\Ssk.txt", System.IO.FileMode.Create)Dim MyWriter As New System.IO.StreamWriter(MyStream, System.Text.Encoding.Default)MyWriter.WriteLine(TextBox1.Text)MyWriter.Flush()MyWriter.Close()MyStream.Close()End Sub'读文本文件Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click'读取一个文本文件 Dim MyReader As New System.IO.StreamReader(Application.StartupPath & "\Ssk.txt", System.Text.Encoding.UTF8)TextBox2.Text = MyReader.ReadToEnd()MyReader.Close()End Sub气斜射入水或其他介质,折射光线与入射光线法线在

G. 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

H. VB.net 读取文本文件

1、实现上传按钮方法代码。

I. VB.net 读取文本文件

ImportsSystem.IOPublicClassForm1PrivateSubForm1_Load(senderAsSystem.Object,eAsSystem.EventArgs)HandlesMyBase.LoadDimsrAsNewStreamReader("d:est.csv")Dimarr1(),arr2(),arr3(),arr4()AsIntegerDima1,a2,a3,a4AsNewArrayListDoUntilsr.EndOfStreamDimstrAsString=sr.ReadLineDims()AsString=str.Split(",")a1.Add(Convert.ToInt32(s(0)))a2.Add(Convert.ToInt32(s(1)))a3.Add(Convert.ToInt32(s(2)))a4.Add(Convert.ToInt32(s(3)))ListBox1.Items.Add(s(0))Looparr1=CType(a1.ToArray(GetType(Integer)),Integer())arr2=CType(a2.ToArray(GetType(Integer)),Integer())arr3=CType(a3.ToArray(GetType(Integer)),Integer())arr4=CType(a4.ToArray(GetType(Integer)),Integer())sr.Close()EndSubEndClass

J. vb.net问题 如何读取一个txt文件的内容并判断

Imports System.IOPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim r As New StreamReader("C:\jq.TXT") '打开文件 Dim Mytxt As String = "" Dim s As String Do While r.Peek > -1 '是否到文件尾 s = r.ReadLine '从打开的文件中读取一行内容 Mytxt = Mytxt & s & vbCrLf '逐行读取文本,并连接到变量Mytxt中 Loop r.Close() '关闭对象 '判断是否与变量相等etjq,略了吧???End SubEnd Class

未经允许不得转载:山九号 » vbnet读取文件内容|怎样用vbnet读取本地txt文件

赞 (0)