资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net获取文件内容,VB读取文件

vb.net 怎样从txt取得内容?

读操作

创新互联-专业网站定制、快速模板网站建设、高性价比涟源网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式涟源网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖涟源地区。费用合理售后完善,十年实体公司更值得信赖。

Dim line As String

Dim sr As StreamReader = New StreamReader(strPath, System.Text.Encoding.Default)

Do While sr.Peek() 0

line = sr.ReadLine()

Loop

sr.Close()

sr = Nothing

注释:

构造函数new

Public Sub New(Path, Encoding)

path:要打开文件的完整路径,如果文件抛出一个错误。

Encoding:缺省值为System.Text.Encoding.Default,即使用系统缺省的编码,指示以什么样的编码读文件。

----------------------------------------------------------------

读取c:\test.txt文件的某行

Set fso = CreateObject("Scripting.FileSystemObject")

Dim LineNumber As Integer

Set ts = fso.OpenTextFile("c:\test.txt", 1)

LineNumber = InputBox("请输入行号")

While Not ts.AtEndOfStream

If ts.Line = LineNumber Then Text1.Text = ts.ReadLine

ts.ReadLine

Wend

ts.Close

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

sr.Close()

fs.Close()

readtext = str

Else

readtext = "操作失败!"

End If

Catch ex As Exception

readtext = "操作失败!"

End Try

End Function

'向指定文件写入数据

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

If path = "" Then

writetext = "操作失败!"

Exit Function

End If

Dim op As FileMode

Select Case opi

Case 1

op = FileMode.Append

Case 2

op = FileMode.Create

Case Else

op = FileMode.Create

End Select

Try

If File.Exists(path) = True Then

Dim fs As New FileStream(path, op)

Dim sr As New StreamWriter(fs)

sr.WriteLine(msg)

sr.Close()

fs.Close()

writetext = "操作完成!"

Else

writetext = "操作失败!"

End If

Catch ex As Exception

writetext = "操作失败!"

End Try

End Function

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)

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

1、新建一个标准的VB EXE工程,只有一个Form,Form上有两个按钮:Command1和Command2。

2、双击Command1添加如下代码

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

3、按F8开始单步调试代码,点击Command1,进入单步调试功能,

4、多次按下F8或直接按下F5运行完成,就完成了读取文本文件内容并输出到立即窗口。

VB.net 读取文本文件?

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

2、判断图片对象是否为空代码。

3、取得数据库字段 dt.Rows(0)("Pic")方法代码。

4、字节数组转换为Image类型方法代码。

5、处理SQL中操作Image类型方法代码。

6、实现的上传结果。


网页名称:vb.net获取文件内容,VB读取文件
路径分享:http://cdkjz.cn/article/hsgiei.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220