zoukankan      html  css  js  c++  java
  • 关于文件的读写

    //写

    string FilePath = Server.MapPath(Request.ApplicationPath)+"\\Error.Txt";//先获得该文件的实际地址
    StreamWriter writer = null;

      if(!File.Exists(FilePath))// 检测有无文件
     {
            File.CreateText(FilePath);  //如果该文件不存在则建立
       }
       writer = File.AppendText(FilePath);//创建流
       writer.WriteLine(DateTime.Now +"@"+Error);//将文本写入
       writer.Close();//关闭

    //读

    //取得文件的实际路径
                string file_path = configpath + "\\counter.txt";

                if(!File.Exists(file_path))
                {
                    File.CreateText(file_path);
                }

                //打开文件进行读取
                using(StreamReader srd = new StreamReader(file_path))
                {
                    try
                    {
                        while(srd.Peek() >= 0)//PEEK返回下一个可用字符但不使用,仅是判断
                        {
                            string str = srd.ReadLine();
                            count = UInt32.Parse(str);
                        }
                    }
                    catch(Exception )
                    {
                        count = 0;
                    }
                }
                object obj = count;
                Application["counter"] = obj;

  • 相关阅读:
    cmake的安装
    安装cmake过程g++: 错误:unrecognized command line option ‘-std=gnu++14’
    进程空间分配
    git 基本操作
    nm命令
    container_of 宏
    cmake
    fiddler修改Requests之前的数据和response 之后的数据
    Fiddler抓包请求前设置断点
    jmeter连接mysql数据库
  • 原文地址:https://www.cnblogs.com/YepQX/p/1686016.html
Copyright © 2011-2022 走看看