News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

How to read and store the file in VB.Net

Started by thiruvasagamani, Jul 23, 2008, 03:18 PM

Previous topic - Next topic

thiruvasagamani

Here is the sample code....copy and paste your environment

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
Thiruvasakamani Karnan