Can two readers access the same file without an exception generated?

I have a StreamReader and a FileStream trying to access the same file (both readers are read-only).  I get an exception--but I figured I would.  Is there a way to get around this?  
LVL 4
NTACAsked:
Who is Participating?
 
s_sansanwalConnect With a Mentor Commented:
I tried this and able to read at same time

                  StreamReader sr = new StreamReader(@"C:\s1.txt");
                  string s = sr.ReadLine();
                  FileStream fs = File.OpenRead(@"C:\s1.txt");
                  byte[] b = new byte[1024];
                  UTF8Encoding temp = new UTF8Encoding(true);
                  while (fs.Read(b,0,b.Length) > 0)
                  {
                        string s1 = temp.GetString(b);
                  }


Just refer it for your code.

Cheers,
S Sansanwal
0
All Courses

From novice to tech pro — start learning today.