T
Tony
{//start Button4
FileStream myFStream = new FileStream (@"C:\Documents
and Settings\Tony\Desktop\testfile.txt",
FileMode.Append, FileAccess.Write);
//FileMode.OpenOrCreate, FileAccess.ReadWrite);
TextWriter txtWrit = new TextWriter (myFStream);
//BinaryWriter binWrit = new BinaryWriter(myFStream);
string testString = "This is a test string.";
txtWrit.Write(testString);
//binWrit.Write(testString);
txtWrit.Close();
//binWrit.Close();
myFStream.Close();
}//End Button4
Looking at some examples I found, I was able to open a file and write
to it in binary mode using the commented out lines above..
Looked at the text in the file and it had a high-ascii char in it.
Thought the logical thing to do would be to use TextWriter instead of
BinaryWriter.
Running the code above though results in an error
C:\Documents and Settings\Tony\My Documents\Visual Studio
Projects\Justmessin\Form1.cs(188): Cannot create an instance of the
abstract class or interface 'System.IO.TextWriter'
I found info at
http://www.functionx.com/vcsharp/fileprocessing/Lesson04.htm
that says
"This class is abstract, meaning you can't initialize a variable with
it. Instead, you can use one of its derived classes, such as the
StreamWriter class."
But I don't understand it really... and why would binaryWriter be ok
to use, but not textWriter...
-Tony!-
FileStream myFStream = new FileStream (@"C:\Documents
and Settings\Tony\Desktop\testfile.txt",
FileMode.Append, FileAccess.Write);
//FileMode.OpenOrCreate, FileAccess.ReadWrite);
TextWriter txtWrit = new TextWriter (myFStream);
//BinaryWriter binWrit = new BinaryWriter(myFStream);
string testString = "This is a test string.";
txtWrit.Write(testString);
//binWrit.Write(testString);
txtWrit.Close();
//binWrit.Close();
myFStream.Close();
}//End Button4
Looking at some examples I found, I was able to open a file and write
to it in binary mode using the commented out lines above..
Looked at the text in the file and it had a high-ascii char in it.
Thought the logical thing to do would be to use TextWriter instead of
BinaryWriter.
Running the code above though results in an error
C:\Documents and Settings\Tony\My Documents\Visual Studio
Projects\Justmessin\Form1.cs(188): Cannot create an instance of the
abstract class or interface 'System.IO.TextWriter'
I found info at
http://www.functionx.com/vcsharp/fileprocessing/Lesson04.htm
that says
"This class is abstract, meaning you can't initialize a variable with
it. Instead, you can use one of its derived classes, such as the
StreamWriter class."
But I don't understand it really... and why would binaryWriter be ok
to use, but not textWriter...
-Tony!-