
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
692
|
Chapter 12: Filesystem I/O
To seek to the beginning of a file, use the following code:
streamWriter.BaseStream.Seek(0, SeekOrigin.Begin);
To seek to the end of a file, use the following code:
streamWriter.BaseStream.Seek(0, SeekOrigin.End);
In these calls, the SeekOrigin enumeration value sets the file pointer to the beginning
or end of a file. The offset, which is zero, does not force the file pointer to move.
With this in mind, realize that using zero as an offset to
SeekOrigin.Current is point-
less because you don’t move the pointer at all, and you are killing clock cycles to no
effect.
See Also
See the “FileStream Class,” “StreamReader Class,” “StreamWriter Class,” “Binary-
Reader Class,” “BinaryWriter Class,” and “SeekOrigin Enumeration” topics in the
MSDN documentation.
12.7 Outputting a Platform-Independent EOL
Character
Problem
Your application will run on more than one platform. Each platform uses a different
end-of-line (EOL) character. You want your code to output the correct EOL character
without having to write code to handle the EOL character specially for each platform.
Solution
The .NET Framework provides the Environment.NewLine constant, which represents a
newline on the given platform. This is the newline string used by all of the framework-
provided
WriteLine methods ...