Home > Net > Use StreamReader constructor to open a TXT file, isn't open read-only?
Use StreamReader constructor to open a TXT file, isn't open read-only?
Time:09-22
Hi,
A simple but don't understand the problem, consult everybody,
C # write a console application, open a as follows. TXT file, read a line,
Using (StreamReader sr=new StreamReader (path)) { The sr. ReadLine (); }
Visual Studio single-step tracking, execute to the ReadLine this line, manually in the file manager to open the path corresponding TXT file, save changes, it can not save!
It.however, this is reader in c #, should be opened read-only, why other processes (such a file manager) used in the experiment, cannot modify saved?
If, in the c # code to achieve a pure "read only" to open a text file, is the new StreamReader (path) way not? So what to do?
Thank you, I wish the programmer the students a happy Spring Festival! ~ ~ ~
CodePudding user response:
Yes, the default FileShare set to FileShare. Read, can use the StreamReader (Stream) constructor