Open a file using StreamWriter : StreamWriter : File Directory Stream C# Examples


C# Examples » File Directory Stream » StreamWriter »

 

Open a file using StreamWriter









    
using  System;  
using  System.IO;  
    
class  MainClass  {  
    public  static  void  Main()  {  
  
        StreamWriter  fstr_out;  
  
        try  {  
            fstr_out  =  new  StreamWriter("test.txt");  
        }  
        catch(IOException  exc)  {  
            Console.WriteLine(exc.Message  +  "Cannot  open  file.");  
            return  ;  
        }  
  
        try  {  
              fstr_out.Write("asdfasdf");  
        }  catch(IOException  exc)  {  
              Console.WriteLine(exc.Message  +  "File  Error");  
              return  ;  
        }  
  
        fstr_out.Close();  
    }  
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» StreamWriter