Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

Detect end of file

I currently have:
try
{
  for (; ; )
  {
    y = r.ReadByte();
  }
}
catch (EndOfStreamException)
{
  //end of file
}

Open in new window

Is there a better way? I feel I shouldn't be using catch for an expected exception.
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deleyd

ASKER

using (FileStream fs = new FileStream(fn, FileMode.Open, FileAccess.Read))
{
  using (BinaryReader r = new BinaryReader(fs))
  {
    try
    {
      for (; ; )
      {
        y = r.ReadByte();
      }
    }
    catch (EndOfStreamException)
    {
      //end of file
    }

Open in new window

SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial