streamreader error

Hi expert,

I have a text file whose content I check is ok; but I could not read this file. Also
I check nobody uses this file in my Pc.
Coud you give me a hand?

Thx,
JT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace streamreader
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                FileStream fs = new FileStream(@"c:\ratetable\Carriername.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                //FileStream fs = new FileStream("c:\\ratetable\\carrierinfo.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                using (StreamReader sr = new StreamReader(fs))
 
                {
                    string strLine = null;
                    while ((strLine = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(strLine);
                    }
                    sr.Close();
                    return;
                }
            }
            catch (IOException err)
            {
                Console.WriteLine("An IO exception has been thrown!");
                Console.WriteLine(err.ToString());
                return;
            }
        }
        
    }
}

Open in new window

carriername.txt.txt
jtran007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
what error on what line?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
note:
the attached file is named Carriername.txt.txt
in the code, you try to open Carriername.txt
maybe ....
0
jtran007Author Commented:
Hi expert,

1- I always get null return but no error

2- I check my file name is carriername.txt

Thx,
JT
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
>2- I check my file name is carriername.txt
can you double-check that, please?
eventually, you have the folder options set to "hide known extensions", and the second .txt would be hidden. check the file properties (right-click in windows explorer) to see, or change the folder options (I hat that setting, btw :)

>1- I always get null return but no error
sounds to me you have meanwhile 2 files:
carriername.txt (empty, created by the code itself due to FileMode.OpenOrCreate)
carriername.txt.txt (the original file)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jtran007Author Commented:
You are right.
0
jtran007Author Commented:
Thanks.
JT
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.