VB.NET質問スレ (Part20) at TECH
VB.NET質問スレ (Part20) - 暇つぶし2ch137:デフォルトの名無しさん
07/03/15 09:51:10
>>125 こんなのでどうか

Public Function ReadTailLines(ByVal filename As String, ByVal lineCount As Integer)
  Dim sep() As String = {vbCrLf}

  Using ifs As IO.FileStream = IO.File.OpenRead(filename)
    Dim allBuf As New List(Of Byte)
    Dim len As Integer = lineCount * 100
    Dim pos As Long = ifs.Length
    Dim lines() As String

    Do
      pos -= len
      If pos < 0 Then
        len += pos
        pos = 0
      End If

      Dim tmpBuf(len) As Byte
      ifs.Seek(pos, IO.SeekOrigin.Begin)
      ifs.Read(tmpBuf, 0, len)

      allBuf.InsertRange(0, tmpBuf)
      lines = Text.Encoding.Default.GetString(allBuf.ToArray(), 0, allBuf.Count).Split(sep, StringSplitOptions.None)
    Loop While pos > 0 And lines.Length < lineCount
(続く)


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch