save up to 40%

How to read text from a newly created data file?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

How to read text from a newly created data file?

Rating:

The steps to read text from a newly created data file are as follows:

  1. Implement the System.IO namespace using the following code.

    using System.IO;

  2. Create a FileStream class object and initialize it with a file name.

    FileStream fs = new FileStream("TestFile.data", FileMode.Open, FileAccess.Read);
    or
    FileStream fs;
    fs = new FileStream("TestFile.data", FileMode.Open, FileAcces.Read);

  3. Create a BinaryReader object and pass the FileStream object in it.

    BinaryReader br = new BinaryReader(fs);


  4. Read text from the file.

    for(int i=1;i<=10;i++)
    Console.WriteLine(br.ReadInt32());

  5. Close the FileStream and BinaryReader stream.

    fs.Close();
    br.Close();


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.