• c#文件操作


    demo1:

            /// <summary>
            /// 将字符串写入到txt文件
            /// </summary>
            /// <param name="filepath"></param>
            /// <param name="contentStr"></param>
            public void WriteTxt(string filepath,string contentStr) {
                if (!File.Exists(filepath))
                {
                    logger.Info("文件不存在");
                    File.CreateText(filepath);
                }
    
                using (StreamWriter sw = new StreamWriter(filepath))
                {
                    sw.WriteLine(contentStr);
                }
            }
    
    
            public string ReadTxt(string filepath)
            {
                StringBuilder sb = new StringBuilder(1024);
                string line;
                using (StreamReader sr = new StreamReader(filepath))
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        sb.AppendLine(line);
                    }
                }
                return sb.ToString();
            }

  • 相关阅读:
    03- CSS进阶
    03-requests使用
    04-scrapy简介
    05-scrapy基本使用
    06-CrawlSpider模板
    07-Request、Response
    03-inotify+rsync sersync lsyncd实时同步服务
    markdown中折叠代码
    02-java基础语法
    01-java简介及环境配置
  • 原文地址:https://www.cnblogs.com/softidea/p/3200049.html
Copyright © 2020-2023  润新知