Reads an ASCII encoded file and writes the text to another file in wide character format : Ascii String Read Write « File Stream « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » File Stream » Ascii String Read WriteScreenshots 
Reads an ASCII encoded file and writes the text to another file in wide character format

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
//  Convert.cs -- Reads an ASCII encoded file and writes the text to another file
//                in wide character format.
//                Compile this program with the following command line:
//                    C:>csc Convert.cs
//
namespace nsConvert
{
    using System;
    using System.Text;
    using System.IO;
    public class Convert
    {
        static public int Main ()
        {
// First, make sure both the input and output files can be opened
            FileStream ostream;
            FileStream istream;
            try
            {
                istream = new FileStream ("Sample.asc", FileMode.Open, FileAccess.Read);
            }
            catch (Exception)
            {
                Console.WriteLine ("Cannot open Sample.asc for reading");
                return (-1);
            }
            try
            {
                ostream = new FileStream ("Sample.wcs", FileMode.Create, FileAccess.ReadWrite);
            }
            catch (Exception)
            {
                Console.WriteLine ("Cannot open Sample.wcs for writing");
                istream.Close ();
                return (-1);
            }
// Create a stream reader and attach the input stream with ASCII encoding
            StreamReader reader = new StreamReader (istream, new ASCIIEncoding());
            string str = reader.ReadToEnd ();
// Create a stream writer and attach the output stream using Unicode encoding
            StreamWriter writer = new StreamWriter (ostream, new UnicodeEncoding());
// Write the text to the file.
            writer.Write (str);
// Flush the output stream
            writer.Flush ();
// Close the streams
            ostream.Close ();
            istream.Close ();
            return (0);
        }
    }
}

//File: Sample.asc
/*
The quick red fox jumps over the lazy brown dog.
Now is the time for all good men to come to the aid of their Teletype.
Peter Piper picked a peck of peppered pickles.

*/

           
       
Related examples in the same category
1.  Demonstrate StringReader and StringWriter  Demonstrate StringReader and StringWriter
2. Manipulating a string read as a line from a file
3. Using String ReaderUsing String Reader
4. An enhanced cipher component that maintains a log fileAn enhanced cipher component that maintains a log file
5. Text ReaderText Reader
w___w__w.jav___a___2__s___.__c_o___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.