예제 #1
0
        /// <summary>
        /// Read a file with given path and return a string array with it's entire contents.
        /// </summary>
        public static string[] ReadAllLines(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 BufferedReader(new FileReader(file));

            try
            {
                var    list = new ArrayList <string>();
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    list.Add(line);
                }
                return(list.ToArray(new string[list.Count]));
            }
            finally
            {
                reader.Close();
            }
        }
예제 #2
0
        /// <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();
            }
        }
예제 #3
0
        /// <summary>
        /// Read a file with given path and return a byte-array with it's entire contents.
        /// </summary>
        public static byte[] ReadAllBytes(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 stream = new FileInputStream(file);

            try
            {
                var array = new byte[file.Length()];
                stream.Read(array, 0, array.Length);
                return(array);
            }
            finally
            {
                stream.Close();
            }
        }
예제 #4
0
파일: File.cs 프로젝트: nguyenkien/api
 /// <summary>
 /// Read a file with given path and return a string array with it's entire contents.
 /// </summary>
 public static string[] ReadAllLines(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 BufferedReader(new FileReader(file));
     try
     {
         var list = new ArrayList<string>();
         string line;
          while ((line = reader.ReadLine()) != null)
          {
              list.Add(line);
          }
         return list.ToArray(new string[list.Count]);
     }
     finally
     {
         reader.Close();
     }
 }
예제 #5
0
        /// <summary>
        /// Delete the file with the given path.
        /// </summary>
        public static void Delete(string path)
        {
            var file = new JFile(path);

            if (file.IsFile())
            {
                file.Delete();
            }
        }
예제 #6
0
파일: File.cs 프로젝트: nguyenkien/api
 /// <summary>
 /// Read a file with given path and return a byte-array with it's entire contents.
 /// </summary>
 public static byte[] ReadAllBytes(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 stream = new FileInputStream(file);
     try
     {
         var array = new byte[file.Length()];
         stream.Read(array, 0, array.Length);
         return array;
     }
     finally
     {
         stream.Close();
     }
 }
예제 #7
0
        /// <summary>
        /// Does a file with given path exist on the filesystem?
        /// </summary>
        public static bool Exists(string path)
        {
            var file = new JFile(path);

            return(file.IsFile() && file.Exists());
        }
예제 #8
0
파일: File.cs 프로젝트: nguyenkien/api
 /// <summary>
 /// Does a file with given path exist on the filesystem?
 /// </summary>
 public static bool Exists(string path)
 {
     var file = new JFile(path);
     return file.IsFile() && file.Exists();
 }
예제 #9
0
파일: File.cs 프로젝트: nguyenkien/api
 /// <summary>
 /// Delete the file with the given path.
 /// </summary>
 public static void Delete(string path)
 {
     var file = new JFile(path);
     if (file.IsFile())
         file.Delete();
 }
예제 #10
0
파일: File.cs 프로젝트: nguyenkien/api
 /// <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();
     }
 }