Exemple #1
0
        /// <summary>
        ///  文件保存
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static bool SaveFile(string filePath, Stream stream)
        {
            bool result = true;

            try
            {
                //if (File.Exists(filePath))
                //{
                //    return false;
                //}
                using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                {
                    byte[] bytes = StreamKit.ToBytes(stream);
                    fileStream.Write(bytes, 0, bytes.Length);
                }
            }
            catch (Exception)
            {
                result = false;
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 返回指定目录下的非UTF8字符集文件
        /// </summary>
        /// <param name="foldPath">路径</param>
        /// <returns>文件名的字符串数组</returns>
        public static string[] FindNoUTF8File(string foldPath)
        {
            StringBuilder sbFile = new StringBuilder();
            DirectoryInfo folder = new DirectoryInfo(foldPath);

            FileInfo[] fileInfos = folder.GetFiles();
            foreach (FileInfo t in fileInfos)
            {
                if (t.Extension.ToLower().Equals(".htm"))
                {
                    FileStream fileStream = new FileStream(t.FullName, FileMode.Open, FileAccess.Read);
                    bool       isUTF8     = StreamKit.IsUTF8(fileStream);
                    fileStream.Close();
                    if (!isUTF8)
                    {
                        sbFile.Append(t.FullName);
                        sbFile.Append("\r\n");
                    }
                }
            }
            return(StringKit.Split(sbFile.ToString(), "\r\n"));
        }