Save string, decimal and char using FileStream and StreamWriter : StreamWriter « File Directory Stream « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
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
SQL Server / T-SQL Tutorial
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# / CSharp Tutorial » File Directory Stream » StreamWriter 
15. 21. 4. Save string, decimal and char using FileStream and StreamWriter
using System;
using System.IO;
using System.Text;

static class MainClass
{
    static void Main()
    {
        // Create a new file.
        using (FileStream fs = new FileStream("test.txt", FileMode.Create))
        {
            using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
            {
                // Write a decimal, string, and char.
                w.WriteLine(124.23M);
                w.WriteLine("Test string");
                w.WriteLine('A');
            }
        }


        // Open the file in read-only mode.
        using (FileStream fs = new FileStream("test.txt", FileMode.Open))
        {
            using (StreamReader r = new StreamReader(fs, Encoding.UTF8))
            {
                // Read the data and convert it to the appropriate data type.
                Console.WriteLine(Decimal.Parse(r.ReadLine()));
                Console.WriteLine(r.ReadLine());
                Console.WriteLine(Char.Parse(r.ReadLine()));
            }
        }

    }
}
124.23
Test string
A
15. 21. StreamWriter
15. 21. 1. new StreamWriter(fs, Encoding.UTF8)
15. 21. 2. Reading and Writing Files
15. 21. 3. Open a file using StreamWriter
15. 21. 4. Save string, decimal and char using FileStream and StreamWriter
15. 21. 5. Create StringWriter from StringBuilder
15. 21. 6. Using StreamWriter: write string
15. 21. 7. Using StreamWriter: write char
15. 21. 8. Using StreamWriter: Writes an Array of characters
15. 21. 9. Using StreamWriter: write a portion of an array
w__w__w___.___j_a___v_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.