+
+#if NET_2_0
+ static File() {
+ _defaultLocalFileTime = new DateTime (1601, 1, 1);
+ _defaultLocalFileTime = _defaultLocalFileTime.ToLocalTime ();
+ }
+
+ //
+ // The documentation for this method is most likely wrong, it
+ // talks about doing a "binary read", but the remarks say
+ // that this "detects the encoding".
+ //
+ // This can not detect and do anything useful with the encoding
+ // since the result is a byte [] not a char [].
+ //
+ public static byte [] ReadAllBytes (string path)
+ {
+ using (FileStream s = Open (path, FileMode.Open, FileAccess.Read, FileShare.Read)){
+ long size = s.Length;
+
+ //
+ // Is this worth supporting?
+ //
+ if (size > Int32.MaxValue)
+ throw new ArgumentException ("Reading more than 4gigs with this call is not supported");
+
+ byte [] result = new byte [s.Length];
+
+ s.Read (result, 0, (int) size);
+
+ return result;
+ }
+ }
+
+ public static string [] ReadAllLines (string path)
+ {
+ using (StreamReader reader = File.OpenText (path)) {
+ return ReadAllLines (reader);
+ }
+ }
+
+ public static string [] ReadAllLines (string path, Encoding encoding)
+ {
+ using (StreamReader reader = new StreamReader (path, encoding)) {
+ return ReadAllLines (reader);
+ }
+ }
+
+ static string [] ReadAllLines (StreamReader reader)
+ {
+ List<string> list = new List<string> ();
+ while (!reader.EndOfStream)
+ list.Add (reader.ReadLine ());
+ return list.ToArray ();
+ }
+
+ public static string ReadAllText (string path)
+ {
+ return ReadAllText (path, Encoding.UTF8Unmarked);
+ }
+
+ public static string ReadAllText (string path, Encoding enc)
+ {
+ using (StreamReader sr = new StreamReader (path, enc)) {
+ return sr.ReadToEnd ();
+ }
+ }
+
+ public static void WriteAllBytes (string path, byte [] data)
+ {
+ using (Stream stream = File.Create (path)) {
+ stream.Write (data, 0, data.Length);
+ }
+ }
+
+ public static void WriteAllLines (string path, string [] lines)
+ {
+ using (StreamWriter writer = new StreamWriter (path)) {
+ WriteAllLines (writer, lines);
+ }
+ }
+
+ public static void WriteAllLines (string path, string [] lines, Encoding encoding)
+ {
+ using (StreamWriter writer = new StreamWriter (path, false, encoding)) {
+ WriteAllLines (writer, lines);
+ }
+ }
+
+ static void WriteAllLines (StreamWriter writer, string [] lines)
+ {
+ foreach (string line in lines)
+ writer.WriteLine (line);
+ }
+
+ public static void WriteAllText (string path, string contents)
+ {
+ WriteAllText (path, contents, Encoding.UTF8Unmarked);
+ }
+
+ public static void WriteAllText (string path, string contents, Encoding enc)
+ {
+ using (StreamWriter sw = new StreamWriter (path, false, enc)) {
+ sw.Write (contents);
+ }
+ }
+
+ private static readonly DateTime _defaultLocalFileTime;
+
+ [MonoLimitation ("File encryption isn't supported (even on NTFS).")]
+ public static void Encrypt (string path)
+ {
+ // MS.NET support this only on NTFS file systems, i.e. it's a file-system (not a framework) feature.
+ // otherwise it throws a NotSupportedException (or a PlatformNotSupportedException on older OS).
+ // we throw the same (instead of a NotImplementedException) because most code should already be
+ // handling this exception to work properly.
+ throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
+ }
+
+ [MonoLimitation ("File encryption isn't supported (even on NTFS).")]
+ public static void Decrypt (string path)
+ {
+ // MS.NET support this only on NTFS file systems, i.e. it's a file-system (not a framework) feature.
+ // otherwise it throws a NotSupportedException (or a PlatformNotSupportedException on older OS).
+ // we throw the same (instead of a NotImplementedException) because most code should already be
+ // handling this exception to work properly.
+ throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
+ }
+#endif