save up to 40%

How to write text to 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 write text to a newly created data file?

Rating:

The steps to write text to 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.Create);
    or
    FileStream fs;
    fs = new FileStream("TestFile.data", FileMode.Create);

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

    BinaryWriter bw = new BinaryWriter(fs);


  4. Write text in the file as follows:

    for(int i=1;i<=10;i++)
       bw.Write((int)i);

  5. Close the FileStream and BinaryWriter 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.