Write formated string to a text file in CSharp

Description

The following code shows how to write formated string to a text file.

Example


  /*from w ww  .j a  v  a 2 s  .c  o m*/

using System;
using System.IO;

class MainClass
{
    public static void Main()
    {
        FileStream f = new FileStream("output.txt", FileMode.Create);
        StreamWriter s = new StreamWriter(f);
        
        s.WriteLine("{0} {1}", "test", 55);
        s.Close();
        f.Close();
    }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip