FileMode.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System.IO
  5. {
  6. // Contains constants for specifying how the OS should open a file.
  7. // These will control whether you overwrite a file, open an existing
  8. // file, or some combination thereof.
  9. //
  10. // To append to a file, use Append (which maps to OpenOrCreate then we seek
  11. // to the end of the file). To truncate a file or create it if it doesn't
  12. // exist, use Create.
  13. //
  14. public enum FileMode
  15. {
  16. // Creates a new file. An exception is raised if the file already exists.
  17. CreateNew = 1,
  18. // Creates a new file. If the file already exists, it is overwritten.
  19. Create = 2,
  20. // Opens an existing file. An exception is raised if the file does not exist.
  21. Open = 3,
  22. // Opens the file if it exists. Otherwise, creates a new file.
  23. OpenOrCreate = 4,
  24. // Opens an existing file. Once opened, the file is truncated so that its
  25. // size is zero bytes. The calling process must open the file with at least
  26. // WRITE access. An exception is raised if the file does not exist.
  27. Truncate = 5,
  28. // Opens the file if it exists and seeks to the end. Otherwise,
  29. // creates a new file.
  30. Append = 6,
  31. }
  32. }