minor CLS conformance tweaks (visibility, virtual, abstract, sealed, etc...)
[mono.git] / mcs / class / corlib / System.IO / File.cs
1 // \r
2 // System.IO.File.cs \r
3 //\r
4 // \r
5 // Authors:\r
6 //   Miguel de Icaza (miguel@ximian.com)\r
7 //   Jim Richardson  (develop@wtfo-guru.com)\r
8 //   Dan Lewis       (dihlewis@yahoo.co.uk)\r
9 //\r
10 // Copyright 2002 Ximian, Inc. http://www.ximian.com\r
11 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved\r
12 //\r
13 \r
14 using System;\r
15 \r
16 namespace System.IO\r
17 {\r
18         /// <summary>\r
19         /// \r
20         /// </summary>\r
21         public sealed class File : Object\r
22         {\r
23                 private File () {}
24
25                 public static StreamWriter AppendText (string path)\r
26                 {       \r
27                         return new StreamWriter (path, true);\r
28                 }\r
29                  \r
30                 public static void Copy (string sourceFilename, string destFilename)\r
31                 {\r
32                         Copy (sourceFilename, destFilename, true);\r
33                 }\r
34                  \r
35                 public static void Copy (string src, string dest, bool overwrite)\r
36                 {       \r
37                         if (src == null || dest == null)\r
38                                 throw new ArgumentNullException ();\r
39                         if (src == "" || dest == null ||\r
40                             src.IndexOfAny (Path.InvalidPathChars) != -1 ||\r
41                             dest.IndexOfAny (Path.InvalidPathChars) != -1)\r
42                                 throw new ArgumentException ();\r
43 \r
44                         if (!MonoIO.CopyFile (src, dest, overwrite))\r
45                                 throw MonoIO.GetException ();\r
46                 }\r
47 \r
48                 public static FileStream Create (string path)\r
49                 {\r
50                         return Create (path, 8192);\r
51                 }\r
52 \r
53                 public static FileStream Create (string path, int buffersize)\r
54                 {\r
55                         return new FileStream (path, FileMode.Create, FileAccess.ReadWrite,\r
56                                                FileShare.None, buffersize);\r
57                 }\r
58                 \r
59                 public static void Delete (string path)\r
60                 {\r
61                         if (path == null)\r
62                                 throw new ArgumentNullException ();\r
63                         if (path == "" || path.IndexOfAny (Path.InvalidPathChars) != -1)\r
64                                 throw new ArgumentException ();\r
65                         \r
66                         if (!MonoIO.DeleteFile (path))\r
67                                 throw MonoIO.GetException ();\r
68                 }\r
69                 \r
70                 public static bool Exists (string path)\r
71                 {\r
72                         return MonoIO.ExistsFile (path);\r
73                 }\r
74 \r
75                 public static FileAttributes GetAttributes (string path)\r
76                 {\r
77                         return MonoIO.GetFileAttributes (path);\r
78                 }\r
79 \r
80                 public static DateTime GetCreationTime (string path)\r
81                 {\r
82                         MonoIOStat stat;\r
83 \r
84                         MonoIO.GetFileStat (path, out stat);\r
85                         return DateTime.FromFileTime (stat.CreationTime);\r
86                 }\r
87 \r
88                 public static DateTime GetLastAccessTime (string path)\r
89                 {\r
90                         MonoIOStat stat;\r
91 \r
92                         MonoIO.GetFileStat (path, out stat);\r
93                         return DateTime.FromFileTime (stat.LastAccessTime);\r
94                 }\r
95 \r
96                 public static DateTime GetLastWriteTime (string path)\r
97                 {\r
98                         MonoIOStat stat;\r
99 \r
100                         MonoIO.GetFileStat (path, out stat);\r
101                         return DateTime.FromFileTime (stat.LastWriteTime);\r
102                 }\r
103 \r
104                 public static void Move (string src, string dest)\r
105                 {\r
106                         if (src == null || dest == null)\r
107                                 throw new ArgumentNullException ();\r
108                         if (src == "" || dest == null ||\r
109                             src.IndexOfAny (Path.InvalidPathChars) != -1 ||\r
110                             dest.IndexOfAny (Path.InvalidPathChars) != -1)\r
111                                 throw new ArgumentException ();\r
112 \r
113                         if (!MonoIO.MoveFile (src, dest))\r
114                                 throw MonoIO.GetException ();\r
115                 }\r
116                 \r
117                 public static FileStream Open (string path, FileMode mode)\r
118                 {       \r
119                         return new FileStream (path, mode, FileAccess.ReadWrite, FileShare.None);\r
120                 }\r
121                 \r
122                 public static FileStream Open (string path, FileMode mode, FileAccess access)\r
123                 {       \r
124                         return new FileStream (path, mode, access, FileShare.None);\r
125                 }\r
126 \r
127                 public static FileStream Open (string path, FileMode mode, FileAccess access,\r
128                                                FileShare share)\r
129                 {\r
130                         return new FileStream (path, mode, access, share);\r
131                 }\r
132                 \r
133                 public static FileStream OpenRead (string path)\r
134                 {       \r
135                         return new FileStream (path, FileMode.Open, FileAccess.Read, FileShare.Read);\r
136                 }\r
137 \r
138                 public static StreamReader OpenText (string path)\r
139                 {\r
140                         return new StreamReader (path);\r
141                 }\r
142 \r
143                 public static FileStream OpenWrite (string path)\r
144                 {\r
145                         return new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);\r
146                 }\r
147 \r
148                 public static void SetAttributes (string path, FileAttributes attributes)\r
149                 {\r
150                         if (!MonoIO.SetFileAttributes (path, attributes))\r
151                                 throw MonoIO.GetException (path);\r
152                 }\r
153 \r
154                 public static void SetCreationTime (string path, DateTime creation_time)\r
155                 {\r
156                         if (!MonoIO.SetFileTime (path, creation_time.Ticks, -1, -1))\r
157                                 throw MonoIO.GetException (path);\r
158                 }\r
159 \r
160                 public static void SetLastAccessTime (string path, DateTime last_access_time)\r
161                 {\r
162                         if (!MonoIO.SetFileTime (path, -1, last_access_time.Ticks, -1))\r
163                                 throw MonoIO.GetException (path);\r
164                 }\r
165 \r
166                 public static void SetLastWriteTime (string path, DateTime last_write_time)\r
167                 {\r
168                         if (!MonoIO.SetFileTime (path, -1, -1, last_write_time.Ticks))\r
169                                 throw MonoIO.GetException (path);\r
170                 }\r
171         }\r
172 }\r