Saturday, February 26, 2011

Read File Using Streams


public static string getFileAsString(string fileName) {
   StreamReader sReader = null;
   string contents = null;
   try {
      FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
      sReader = new StreamReader(fileStream);
      contents = sReader.ReadToEnd();
   } finally {
     if(sReader != null) {
         sReader.Close();
      }
   }
   return contents;
}

No comments:

Post a Comment

Your comment is pending for approval

AngularJS Basics - Part 1

                                                                  AngularJS What is AngularJS ·          Framework by googl...