zoukankan      html  css  js  c++  java
  • IO流操作

    向文件新增一行

    /// <summary>
            /// 记录bug,以便调试
            /// </summary>
            /// <returns></returns>
            public bool WriteTxt(string str)
            {
                try
                {
                    FileStream fs = new FileStream(Server.MapPath("/bugLog.txt"), FileMode.Append);
                    StreamWriter sw = new StreamWriter(fs);
                    //开始写入
                    sw.WriteLine(str);
                    //清空缓冲区
                    sw.Flush();
                    //关闭流
                    sw.Close();
                    fs.Close();
                }
                catch (Exception)
                {
                    return false;
                }
                return true;
            }

    读取数据

     public string ReaderTxt()
            {
                string sLine = "";
                try
                {
                    StreamReader objReader = new StreamReader(Server.MapPath("/bugLog.txt"));
                    sLine = objReader.ReadToEnd();
                    objReader.Close();
                }
                catch (Exception)
                {
                    sLine = "读取失败";
                }
                return sLine;
            }

    一行一行读取

    private void WriteXML()
            {
                string sLine = "";
                try
                {
                    Encoding en = Encoding.GetEncoding("GB2312");
                    StreamReader objReader = new StreamReader(Server.MapPath("/cityCode.txt"),en);
    
                    while ((sLine = objReader.ReadLine()) != null) //每次读取一行
                    {
                        Response.Write(sLine);//html输出行
                    }
    
                    objReader.Close();
                }
                catch (Exception)
                {
                    sLine = "读取失败";
                }
            }
  • 相关阅读:
    java的概述 常量 变量
    css 基础2
    css 盒子模型1
    css 基础1
    HTML 基础 3
    HTML基础2
    servletContext百科
    hibernate 一对多双向关联 详解
    hibernate generator class="" id详解
    Hibernate缓存原理与策略
  • 原文地址:https://www.cnblogs.com/hougelou/p/2854758.html
Copyright © 2011-2022 走看看