Imports System.IO
Imports System.ComponentModel
Imports FileObject.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     'czy plik istnieje
      File.Delete("foo.txt")           'jeśli tak, usuń go
    End If
    'otwarcie plików
    Dim ts As StreamReader
    Dim fs As FileStream

    ts = File.OpenText("foo.txt")  'otwarcie pliku tekstowego do odczytu
    fs = File.OpenRead("foo.data") 'otwarcie dowolnego pliku do odczytu
    'czytanie z pliku
    Dim s As String
    s = ts.ReadLine()
    'zapisanie pliku tekstowego
    Dim sw As StreamWriter
    sw = File.CreateText("foo.txt")
    sw.WriteLine("Hello there")

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

    'wyjątki
    Try
      ts = File.OpenText("foo.txt")
    Catch e As FileNotFoundException
      'wyświetlenie infromacji o błędzie
      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
