Exemplo n.º 1
0
        /// <summary>
        /// 获取日志文件路径 以指定时间计算
        /// </summary>
        private string GetLogFilePath()
        {
            string directory = string.Format("/Logs/{0}/{1}Year/{2}Month/{3}Day",
                                             this.Type.ToString(),
                                             this.AddTime.Year,
                                             this.AddTime.Month,
                                             this.AddTime.Day);
            string file = string.Format("{0}Hour.log", this.AddTime.Hour);

            return(PathHelp.CreateUseFilePath(directory, file));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 只读文件内容
        /// </summary>
        /// <param name="file_path">文件路径</param>
        /// <param name="encoding">文件编码</param>
        /// <returns></returns>
        public static string OnlyRead(string file_path, Encoding encoding)
        {
            string abs_file_path = PathHelp.ToAbsolute(file_path);

            if (CheckData.IsStringNull(abs_file_path))
            {
                return(string.Empty);
            }
            PathHelp.CreateFileExists(abs_file_path);
            using (FileStream rfs = File.OpenRead(abs_file_path)) {
                using (StreamReader sr = new StreamReader(rfs, encoding)) {
                    string content = sr.ReadToEnd();
                    return(content);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 只写文件内容
        /// </summary>
        /// <param name="file_path">文件路径</param>
        /// <param name="content">写入内容</param>
        /// <param name="encoding">文件编码</param>
        public static void OnlyWrite(string file_path, string content, Encoding encoding)
        {
            string abs_file_path = PathHelp.ToAbsolute(file_path);

            if (CheckData.IsStringNull(abs_file_path))
            {
                return;
            }
            content = ConvertTool.ToString(content);
            File.Delete(abs_file_path);
            PathHelp.CreateFileExists(abs_file_path);
            using (FileStream wfs = File.OpenWrite(abs_file_path)) {
                using (StreamWriter sw = new StreamWriter(wfs, encoding)) {
                    sw.Write(content);
                    sw.Flush();
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 获得系统自动生成文件夹相对路径
 /// </summary>
 public static string SystemAutoGeneratesFolder()
 {
     return(string.Format("/{0}", PathHelp.ToPathSymbol(Const.Names.SYSTEM_AUTO_GENERATES_PATH)));
 }