
Imports System.IO
Imports System.ComponentModel
Imports FileStreamObject.VBPatterns

Public Class FileTest

  Public Sub New()
    MyBase.New()
    Dim fl As vbFile
    Dim s As String

    fl = New vbFile("500free.txt")
    fl.OpenForRead()
    s = fl.readLine

    While Not (fl.fEOF)
      Console.WriteLine(s)
      s = fl.readLine
    End While
    fl.closeFile()

    Dim outf As New vbFile("outTest.txt")
    outf.OpenForWrite()
    outf.writeText("file write test")
    outf.closeFile()
  End Sub
  Private Sub fDemo()
    Dim errFlag As Boolean
    'użycie obiektu File
    If File.Exists("foo.txt") Then  'sprawdzenie istnienia pliku
      File.Delete("foo.txt")        'usuń go jeśli istnieje
    End If
    'otwarcie plików
    Dim ts As StreamReader
    Dim fs As FileStream

    ts = File.OpenText("foo.txt")  'otwórz do odczytu plik tekstowy
    fs = File.OpenRead("foo.data") 'otwórz dowolny plik do odczytu
    'odczyt z pliku
    Dim s As String
    s = ts.ReadLine()
    'zapis do pliku tekstowego
    Dim sw As StreamWriter
    sw = File.CreateText("foo.txt")
    sw.WriteLine("Hello there")

    'dopisywanie
    sw = New StreamWriter("foo.txt", True)

    'wyjątki
    Try
      ts = File.OpenText("foo.txt")
    Catch e As FileNotFoundException
      'wyświetl opis błędu
      Console.WriteLine(e.Message)
      errFlag = True
    End Try

  End Sub

  Public Shared Sub Main()
    Dim ft As FileTest
    ft = New FileTest()
  End Sub

End Class
