Esempio n. 1
0
 public static bool Create(string file, string txt)
 {
     try
     {
         DirTool.Create(Path.GetDirectoryName(file));
         using (StreamWriter sw = new StreamWriter(file, false, Encoding.UTF8))
         {
             sw.WriteLine(txt);
         }
         return(true);
     }
     catch (Exception e) { }
     return(false);
 }
Esempio n. 2
0
        /// <summary>
        /// 获取文件的MD5特征码
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        //public static string GetMD5(string file)
        //{
        //    string result = string.Empty;
        //    if (!File.Exists(file)) return result;

        //    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
        //    {
        //        HashAlgorithm algorithm = MD5.Create();
        //        byte[] hashBytes = algorithm.ComputeHash(fs);
        //        result = BitConverter.ToString(hashBytes).Replace("-", "");
        //    }
        //    return result;
        //}
        /// <summary>
        /// 获取多个文件的MD5特征码
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        //public static string[] GetMD5(List<string> files)
        //{
        //    string[] result = new string[files.Count];
        //    for (int i = 0; i < files.Count; i++)
        //    {
        //        result[i] = GetMD5(files[i]);
        //    }
        //    return result;
        //}
        public static bool Copy(string sourceFileName, string destFileName, bool overwrite)
        {
            if (File.Exists(sourceFileName))
            {
                string destPath = DirTool.GetFilePath(destFileName);
                if (DirTool.Create(destPath))
                {
                    try
                    {
                        File.Copy(sourceFileName, destFileName, overwrite);
                        return(true);
                    }
                    catch { }
                }
            }
            return(false);
        }
Esempio n. 3
0
 public static bool Append(string file, List <string> txt)
 {
     try
     {
         DirTool.Create(Path.GetDirectoryName(file));
         using (StreamWriter sw = new StreamWriter(file, true))
         {
             if (!ListTool.IsNullOrEmpty(txt))
             {
                 foreach (var t in txt)
                 {
                     sw.WriteLine(t);
                 }
             }
         }
         return(true);
     }
     catch (Exception e) { }
     return(false);
 }