Thursday, 4 July 2013

USING TEXT FILES IN VB.NET (VISUAL STUDIO 2010)

    USING TEXT FILES IN VB.NET (VISUAL STUDIO 2010)




Files are good means of transfer of data during Runtime in An Application . 

FILES ARE BETTER IF WE HAVE LESS AMOUNT OF DATA TO SEND AND RECEIVE FROM TEXTFILES.

FOR SMALL APPLICATIONS FILES ARE BETTER AS COMPARED TO DATABASE BECAUSE DATABASE CONSUMES MORE TIME AS COMPARED TO TEXTFILES FOR FETCHING DATA FROM DATABASE

BUT FOR LARGE APPLICATIONS FILES ARE CONSIDERED TO BE UNABLE TO MANAGE LARGE DATA IN WELL-DEFINED ORGANISED WAY.

STREAMREADER is Used in Visual Basic . NET to Read Data from TextFiles . An Object is first created of type streamreader that is inbuilt class described under Namespace System.io.Streamreader

STREAMWRITER is Used In Visual Basic .Net to Write Data to TextFiles. An Object is first created of type streamwriter that is inbuilt class described under Namespace System.io.Streamwriter

peek() function is used to detect the end of file while reading the data from file


EXAMPLE TO SHOW USE OF FILES :-

READ DATA FROM TEXT FILE

Create Reader Object 

A File is read by creating a file Reader object is created by declaring a object of type system.io.streamreader Namespace as follows :-

Dim objreader As  System.IO.StreamReader = New System.IO.StreamReader( "path of text file" )

Here
           objreader is object of type streamreader in system.io Class That is used to read the Stream of Data From Text files . An object is similar like we create a variable of basic Data Types .
          
            System - It is a Main Namespace 
            IO - It is a Sub namespace included in system Namespace
            Streamreader - It is a Class of Type IO Namespace

Read Data

TextBox1.Text = objreader.ReadLine() --------(1)
In this Streamreader object objreader reads Single line from TextFile Whose path is given

TextBox1.Text = objreader.Read()-------------(2)
In this Streamreader object objreader reads Single Characte from TextFile Whose path is given

TextBox1.Text = objreader.ReadToEnd()------(3)
In this Streamreader object objreader reads Whole Data from TextFile Whose path is given



WRITE DATA TO TEXT FILE



A File is written by creating a file writter object is created by declaring a object of type system.io.streamwriter Namespace as follows :-



Dim objwriter As  System.IO.StreamWriter = New System.IO.StreamWriter( "path of text file" )

Here, 
           objwriter is object of type streamwriter in system.io Class That is used to write the Stream of Data to Text files . An object is similar like we create a variable of basic Data Types .
          
            System - It is a Main Namespace 
            IO - It is a Sub namespace included in system Namespace
            Streamwriter - It is a Class of Type IO Namespace

Write Data

TextBox1.Text = objwriter.Writeline() --------(1)
In this StreamWriter object objwriter Writes Single line To TextFile Whose path is given

TextBox1.Text = objreader.Read()-------------(2)
In this StreamWriter object objwriter Writes Single Characte To TextFile Whose path is given

Share this

0 Comment to "USING TEXT FILES IN VB.NET (VISUAL STUDIO 2010)"

Post a Comment