In order to read and write to a sequential file, I am using Streamreader and streamwriter classes. and it works fine.
In a book which I am going thru, first a "FileStream" object is created.
why do I need a "FileStream" object?
thanks
nath
Printable View
In order to read and write to a sequential file, I am using Streamreader and streamwriter classes. and it works fine.
In a book which I am going thru, first a "FileStream" object is created.
why do I need a "FileStream" object?
thanks
nath
I meant for example:
FileStream stmWeekdays = new FileStream("Weekdays.txt", FileMode.Create, FileAccess.Write, FileShare.None);
StreamWriter stmWriter = new StreamWriter(stmWeekdays);
why can't I pass the path name of the file while creating stmWriter object.
I don't understand the benefit of using FileStream object.
thanks
nath
You can pass the name of the file. The thing is, you need a FileStream regardless. If you pass the name of the the file to the StreamReader or StreamWriter constructor then it simply creates the FileStream for you. A reference to that FileStream can then be retrieved through the BaseStream property.
Hello jm,
could you give me an example with brief explanation ?
thank you so much
nath
Books don't specify the best way to do things (Not so often)
They aim to using as much classes as possible so you learn their usability
If you want an example then go to the MSDN library. The topic for each StreamWriter constructor has the same code example that shows how to use each of them. MSDN should always be your first stop.