A simple disk-to-screen utility that demonstrates a FileReader : FileStream : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » FileStream »

 

A simple disk-to-screen utility that demonstrates a FileReader









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/

/* A simple disk-to-screen utility that 
   demonstrates a FileReader. */ 
 
using System; 
using System.IO;  
 
public class DtoS { 
  public static void Main() { 
    FileStream fin; 
    string s; 
 
    try { 
      fin = new FileStream("test.txt", FileMode.Open); 
    } 
    catch(FileNotFoundException exc) { 
      Console.WriteLine(exc.Message + "Cannot open file."); 
      return ; 
    }  
 
    StreamReader fstr_in = new StreamReader(fin); 
 
    // Read the file line-by-line. 
    while((s = fstr_in.ReadLine()) != null) { 
      Console.WriteLine(s); 
    } 
 
    fstr_in.Close(); 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» FileStream