Exforsys.com
 
Home Tutorials VB.NET 2005
 

Working with File System in .NET

 

Working with File System in .NET - Page 2

Page 2 of 2

.
.
.




Using StreamReader and StreamWriter Classes

StreamReader is useful for reading lines of information from standard text file and StreamWriter is useful for writing to standard text files. We shall see a an example that illustrates these functions.


  1. Create a new Visual Basic Windows project.
  2. Add a Label, a RichTextBox and four Buttons.
  3. Arrange them on the form as shown in the following screenshot.



We are using the methods of FileStream, StreamReader and StreaWriter to create a file, write data to it and read from the file. The codes for the program are given below:


Click here to view sample code


The out put window and the text file the program has generated are shown below:


Opening Screen With text:



The program window after writing and reading Twice:
.


The text file created is shown below:







Using BinaryReader and BinaryWriter Classes




BinaryWriter class is used to write binary data to a file. The BinaryReader is useful to us for reading the data from the BinaryFile. Let us see an illustration of the utilities of this class.

  1. Create a new project as Windows Application.
  2. Add two Buttons, a Label and a RichTextBox t the form.
  3. Arrange the controls so that the form looks like the screenshot given below:




Now add the following code to the form.


Click here to view sample code


This program will create a binary file and also read the binary file. Now press F5 to execute the program. A form will appear. Click the button ReadWrite. The output of the program is shown below:



The bin file that was created by this action is opened with text editor and shown below:





First Page: Working with File System in .NET


Read Next: ADO.NET Object Model



 

 

Comments


Kel said:

  I'm wanting to append many text files together in a given directory(say kel.txt,kel1.text,kel3.txt,kel4.txt exist in a directory i.e C:Temp) How can i append them together and save resulting data in a .txt file called appendText.txt.
can anyone help..
cheers
May 3, 2007, 8:01 am

Muhammad Awais said:

  This is very good article. This article helped me very much in Stringreader and stringwriter . Very nice.
September 17, 2007, 3:49 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape