In C++, you open a stream like so:
int variable = 45;
ifstream iFile = new ifstream("nameoffile"); // Declare + Open the Stream
// iFile.open("nameofIle");
iFile >> variable;
iFile.close
I'm trying to understand C# FileStream
. The read and write methods require an array and offset and count. This array how big is the array? Do I just give it any size and it will fill it up? If that's the case, how do I go about reading a file with Filestream
?
How do I know how big of an array I pass in?
You can simply use StreamReader
and StreamWriter
wrappers to read and write:
using(StreamReader sr = new StreamReader(fileName))
{
var value = sr.ReadLine(); // and other methods for reading
}
using (StreamWriter sw = new StreamWriter(fileName)) // or new StreamWriter(fileName,true); for appending available file
{
sw.WriteLine("test"); // and other methods for writing
}
or do like the following:
StreamWriter sw = new StreamWriter(fileName);
sw.WriteLine("test");
sw.Close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With