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;

  • 相关阅读:
    SeaweedFS上手使用指南
    XyTalk企业即时通讯IM开始开源
    大数据项目相关技术栈(Hadoop周边技术)
    Hive SQL基础操作
    Applet Mode
    快速开始
    NetBeans启动Tomcat报“'127.0.0.1' 不是内部或外部命令”启动失败的解决办法
    运行带distance field的Hiero
    Game Loop的几种实现方式
    20150408
  • 原文地址:https://www.cnblogs.com/YepQX/p/1686016.html
Copyright © 2011-2022 走看看