本文整理汇总了VB.NET中System.IO.FileInfo.OpenText方法的典型用法代码示例。如果您正苦于以下问题:VB.NET FileInfo.OpenText方法的具体用法?VB.NET FileInfo.OpenText怎么用?VB.NET FileInfo.OpenText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.OpenText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: OpenTextTest
' 导入命名空间
Imports System.IO
Imports System.Text
Public Class OpenTextTest
Public Shared Sub Main()
Dim path As String = "c:\MyTest.txt"
Dim fi As New FileInfo(path)
' Check for existing file
If fi.Exists = false Then
' Create the file.
Dim fs As FileStream = fi.Create()
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 = fi.OpenText()
Dim s As String = ""
While sr.EndOfStream = false
s = sr.ReadLine()
Console.WriteLine(s)
End While
sr.Close()
End Sub
End Class
'This code produces output similar to the following;
'results may vary based on the computer/file structure/etc.:
'
'This is some text in the file.
'