using System; using System.IO; class TextRW { static void Main() { TextWriter stringWriter = new StringWriter(); using(TextWriter streamWriter = new StreamWriter("InvalidPathChars.txt")) { WriteText(stringWriter); WriteText(streamWriter); } TextReader stringReader = new StringReader(stringWriter.ToString()); using(TextReader streamReader = new StreamReader("InvalidPathChars.txt")) { ReadText(stringReader); ReadText(streamReader); } } static void WriteText(TextWriter textWriter) { textWriter.Write("Invalid file path characters are: "); textWriter.Write(Path.InvalidPathChars); textWriter.Write('.'); } static void ReadText(TextReader textReader) { Console.WriteLine("From {0} - {1}", textReader.GetType().Name, textReader.ReadToEnd()); } }