/// <summary> /// Read a file with given path and return a string with it's entire contents. /// </summary> public static string ReadAllText(string path) { if (path == null) { throw new ArgumentNullException("path"); } var file = new JFile(path); if (!file.Exists() || !file.IsFile()) { throw new FileNotFoundException(path); } if (!file.CanRead()) { throw new UnauthorizedAccessException(path); } var reader = new FileReader(file); try { var array = new char[4096]; var buffer = new StringBuffer(); int len; while ((len = reader.Read(array, 0, array.Length)) > 0) { buffer.Append(array, 0, len); } return(buffer.ToString()); } finally { reader.Close(); } }
/// <summary> /// Read a file with given path and return a string with it's entire contents. /// </summary> public static string ReadAllText(string path) { if (path == null) throw new ArgumentNullException("path"); var file = new JFile(path); if (!file.Exists() || !file.IsFile()) throw new FileNotFoundException(path); if (!file.CanRead()) throw new UnauthorizedAccessException(path); var reader = new FileReader(file); try { var array = new char[4096]; var buffer = new StringBuffer(); int len; while ((len = reader.Read(array, 0, array.Length)) > 0) { buffer.Append(array, 0, len); } return buffer.ToString(); } finally { reader.Close(); } }