VB.Net/File Directory/FileStream — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:40, 26 мая 2010

Use FileStream to store and read file

Imports System
Imports System.IO
Public Class MainClass
  Shared Sub Main()
    Dim i As Integer
    Dim theBytes(255) As Byte
    For i = 0 To 255
      theBytes(i) = CByte(i)
    Next
    Dim myFileStream As FileStream
    Try
      myFileStream = New FileStream("test.txt", FileMode.OpenOrCreate, FileAccess.Write)
      myFileStream.Write(theBytes, 0, 256)
    Finally
      If Not (myFileStream Is Nothing) Then myFileStream.Close()
    End Try

    Dim theFile As FileStream
    Try
      theFile = New FileStream("test.txt",FileMode.Open, FileAccess.Read)
      For i = 0 To (theFile.Length - 1)
        Console.Write(theFile.ReadByte)
      Next
    Catch e As Exception
      Throw e
    Finally
      If Not (theFile Is Nothing) Then theFile.Close()
    End Try
  End Sub
  
End Class