Is2215 lecture6 lecturer_file_access

328 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
328
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Is2215 lecture6 lecturer_file_access

  1. 1. Sequential FilesFILE ACCESS
  2. 2. System.IO File Handling in VB.NET is based on the System.IO Namespace It contains a class library that allows for string, character and file manipulation These classes allow us to:  Read  Write  Copy  Delete  Manipulate Files VB .NET IO Namespace
  3. 3. Commonly Used IO Classes File Stream Class:  provides access to standard input and output files StreamReader and StreamWriter Class:  classes enables us to read or write a sequential stream of characters to or from a file BinaryReader and BinaryWriter Class  The BinaryReader and BinaryWriter classes enable us to read and write binary data, raw 0s and 1s
  4. 4. Creating a Sequential File Use the StreamWriter Class Choose a Filename (256 characters max) Choose a file path for the folder to contain the file Execute the a statement in the form of: Dim sw as IO.StreamWriter = _ IO.File.CreateText(filespec) Place data into the file using the WriteLine Method sw.WriteLine(“text”) After data has been placed close the StreamWriter sw.close
  5. 5. Reading a Sequential File Use the StreamReader class to open the file for input Select the File to Use Read from the file using the ReadLine Method
  6. 6. Adding to a Sequential File Use the StreamWrite to open the file for appendingDim sw As IO.StreamWriter = _ IO.File.AppendText(filespec) Place data into the File Using WriteLine method Once you have finished writing to the file close the StreamWriter
  7. 7. Another ExampleStreamWriter/Reader with Search Functionality
  8. 8. Other File Mg’t Operations Delete a File IO.File.Delete(filespec) Move IO.File.Delete(filespec, newfilespec) You can simplify code by using Imports System.IO

×