zoukankan      html  css  js  c++  java
  • 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();
            }

  • 相关阅读:
    [LeetCode] 771. Jewels and Stones
    [LeetCode] 129. Sum Root to Leaf Numbers
    java定时器demo
    Spring Boot与监控管理
    springboot与热部署
    springboot中的web项目不能访问templates中的静态资源
    @Component 和 @Bean 的区别
    springcluoud入门
    Dubbo和Zookerper的关系
    Spring boot配置Dubbo三种方式
  • 原文地址:https://www.cnblogs.com/softidea/p/3200049.html
Copyright © 2011-2022 走看看