Link to home
Start Free TrialLog in
Avatar of jtran007
jtran007

asked on

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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

what error on what line?
note:
the attached file is named Carriername.txt.txt
in the code, you try to open Carriername.txt
maybe ....
Avatar of jtran007
jtran007

ASKER

Hi expert,

1- I always get null return but no error

2- I check my file name is carriername.txt

Thx,
JT
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg 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
You are right.
Thanks.
JT