VB.net缓冲流的校正

Posted dzweather

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB.net缓冲流的校正相关的知识,希望对你有一定的参考价值。

缓冲流可以起到提高效率的作用,但要小心使用,容易出现问题,对比下面。

Imports System.IO

Module Module1

    Sub Main()
        Dim path As String = "D:\\Test.txt" '内容为123456
        Dim sr As StreamReader = New StreamReader(path)
        Dim c(3) As Char

        sr.Read(c, 0, c.Length)
        Console.WriteLine(c) '1234

        sr.DiscardBufferedData()
        sr.BaseStream.Seek(4, SeekOrigin.Begin)
        Console.WriteLine(sr.ReadToEnd())
        '无sr.DiscardBufferedData()时结果为:5656
        '有sr.DiscardBufferedData()时结果为:56     重置校正,但会降低性能
        sr.Close()
    End Sub

End Module

以上是关于VB.net缓冲流的校正的主要内容,如果未能解决你的问题,请参考以下文章