Are there mistakes in reading file? I've recently made a test. There were four tasks. One of them was to improve following code:

public class FooFileProcessor
{
    public void ProcessFile(string filename)
    {
       Stream fileStream = File.OpenRead(filename);
       Console.WriteLine(ReadAllContent(fileStream));
       fileStream.Close();
    }

    public string ReadAllContent(Stream stream)
    {
       StreamReader streamReader = new StreamReader(stream);
       return streamReader.ReadToEnd();
    }
}


What I've suggested:

try
{ 
    using (StreamReader sr = new StreamReader("TestFile.txt"))
    {
       String line = sr.ReadToEnd();
       Console.WriteLine(line);
    }
}
catch (Exception e)        
{
   Console.WriteLine("The file could not be read:");
   Console.WriteLine(e.Message);
}


please, review my code and show all mistakes you've seen.
The first thing that springs to mind is that it would probably be better to not create the Stream and StreamReader instances when it can be avoided simply by using the File.ReadAllText method to accomplish the same goal:

public void ProcessFile(string filename)
{
   Console.WriteLine(File.ReadAllText(filename));
}


In other situations you might need to avoid this, especially for very large files.  For small files and simple operations the File.Read... methods should suffice.

Main advantage is that you relegate the object management issues to the framework, reducing the complexity of your code.  This should result in fewer bugs and greater readability.

For larger files, especially where you are wanting to process individual lines (a common use case) it is often useful to use the File.ReadLines method to process the content.  This should read the lines as needed with some buffering, reducing memory consumption while maintaining code simplicity.



On the question of exception handling... I prefer to only put exception handling in when it is required by the specific situation, and I didn't see a specific need here.  If the idea of an exception breaking out of this code concerns you then by all means add some in.  Personally I'd prefer to have the exception bubble out than have to write all the extra code in here to not only handle the exception but also change what we do with a null return, etc.

In general I don't like the idea of always trying to catch exceptions as soon as possible.  I prefer to catch as soon as I need to and no sooner.