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

image_pdfimage_print


   

/*
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(); 
  } 
}


           
          


This entry was posted in File Stream. Bookmark the permalink.