File Handling in VB.NET

  • Thread starter Thread starter Jody
  • Start date Start date
Jody:

Dim lsFileContent as String

'Opens the file name referred to as sFileName.
Dim lfsTemp = New FileStream(sFileName, IO.FileMode.Open)

'Creates a Binary reader object.
Dim lbrTemp = New BinaryReader(lfsTemp)

'Reads all the bytes.
Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)

' Since I am reading bytes, they could also be multi-byte and
' this method uses the encoding to convert the bytes read to a
string
lsFileContent = System.Text.Encoding.Default.GetString(lbTemp)

lfsTemp.Close
lbrTemp.Close

Hope this helps.

Venki
 
Back
Top