Mono Class Library: Mono.Unix NamespaceMono.Unix.StdioFileStream Class |
See Also: StdioFileStream Members
System.IO.Stream
Mono.Unix.StdioFileStream
|
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
Mono.Unix.StdioFileStream is used for reading and writing files on a file system and interoperating with the standard ANSI/ISO C FILE pointer data type.
Mono.Unix.StdioFileStream objects support random access to files using the System.IO.Stream.Seek(long, System.IO.SeekOrigin) method, and the System.IO.Stream.CanSeek properties of Mono.Unix.StdioFileStream instances encapsulating files are set to true. The System.IO.Stream.Seek(long, System.IO.SeekOrigin) method allows the read/write position to be moved to any position within the file. This is done with byte offset reference point parameters. The byte offset is relative to the seek reference point, which can be the beginning, the current position, or the end of the underlying file, as represented by the three values of the System.IO.SeekOrigin enumeration.
If a Mono.Unix.StdioFileStream encapsulates a device that does not support seeking, its System.IO.FileStream.CanSeek property is false.
Note: For additional information, see System.IO.Stream.CanSeek.The following example demonstrates the use of a Mono.Unix.StdioFileStream object.
C# Example using System; using System.IO; using Mono.Unix; class Directory { public static void Main(String[] args) { StdioFileStream fs = new StdioFileStream ("log.txt", "ab"); StreamWriter w = new StreamWriter(fs); Log ("Test1", w); Log ("Test2", w); w.Close(); // Close the writer and underlying file. fs = new StdioFileStream("log.txt", "rb"); StreamReader r = new StreamReader(fs); r.BaseStream.Seek(0, SeekOrigin.Begin); DumpLog (r); } public static void Log (String logMessage, StreamWriter w) { w.Write("Log Entry : "); w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString()); w.WriteLine(":"); w.WriteLine(":{0}", logMessage); w.WriteLine ("-------------------------------"); w.Flush(); } public static void DumpLog (StreamReader r) { while (r.Peek() > -1) { // While not at the end of the file, write to standard output. Console.WriteLine(r.ReadLine()); } r.Close(); } }Some example output is
Log Entry : 9:26:21 AM Friday, July 06, 2001
:
:Test1
-------------------------------
Log Entry : 9:26:21 AM Friday, July 06, 2001
:
:Test2
-------------------------------
[Edit]
Namespace: Mono.Unix
Assembly: Mono.Posix (in Mono.Posix.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0