zoukankan      html  css  js  c++  java
  • C#读取文件

        protected void Button1_Click(object sender, EventArgs e)
        {
            using (StreamWriter w = File.AppendText("log.txt"))//追边文件
            {
                Log("Test1", w);
                Log("Test2", w);
                // Close the writer and underlying file.
                w.Close();
            }
            // Open and read the file.
            using (StreamReader r = File.OpenText("log.txt"))//读取文件
            {
                DumpLog(r);
            }


        }

    public static void Log(string logMessage, TextWriter w)//
        {
            w.Write("\r\nLog Entry : ");
            w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
                DateTime.Now.ToLongDateString());
            w.WriteLine("  :");
            w.WriteLine("  :{0}", logMessage);
            w.WriteLine("-------------------------------");
            // Update the underlying file.
            w.Flush();
        }

        public static void DumpLog(StreamReader r)
        {
            // While not at the end of the file, read and write lines.
            string line;
            while ((line = r.ReadLine()) != null)
            {
                Console.WriteLine(line);
               
            }
            r.Close();
        }

  • 相关阅读:
    JavaScript之延迟加载
    Android之adb命令
    Android之所有API汇总
    Android常用系统广播
    CSS之自适应布局webkit-box
    在Go中没有引用传值
    go指针-1
    go如何实现优雅的错误处理,
    Golang中切片复制成本,一个大切片会比小切片占用更多内存吗?
    Go中的Slice有何不同,传递类型,详解切片类型
  • 原文地址:https://www.cnblogs.com/lucky_dai/p/2038984.html
Copyright © 2011-2022 走看看