• 文件写入写出的封装




        #region 文件写入写出的封装
        /// <summary>
        /// 写入文件方法
        /// </summary>
        /// <param name="filePath">要被写入的文件的路径</param>
        /// <param name="fileConten">要被写入内容</param>
        /// <returns></returns>
        public bool  StreamWrite(string filePath,string fileConten,HttpServerUtility Server)
        {
            try
            {
                string content = fileConten.ToString();
                string path = Server.MapPath(filePath);
                StreamWriter strwriterobj = new StreamWriter(path, false, System.Text.Encoding.GetEncoding("GB2312"));
                strwriterobj.WriteLine(content);
                strwriterobj.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 读取文件方法
        /// </summary>
        /// <param name="filePath">要被读取的文件的路径</param>
        /// <param name="boxCon">接收内容的文本框</param>
        /// <returns></returns>
        public bool StreamRead(string filePath,TextBox boxCon,HttpServerUtility Server)
        {
            try
            {
                string path = Server.MapPath(filePath);
                StreamReader sr = new StreamReader(path, System.Text.Encoding.GetEncoding("GB2312"), true);
                boxCon.Text = sr.ReadLine().ToString();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion
  • 相关阅读:
    11.06第十次作业
    (构造方法私有化、this)10.29练习题
    10.23创造人
    10.16(RuPeng)游戏
    10.09
    作业9.25
    练习题
    (随机数之和)求一整数各位数之和1636050052王智霞
    两点之间的距离1636050052王智霞
    TabLayout 简单使用。
  • 原文地址:https://www.cnblogs.com/wantingqiang/p/1206668.html
Copyright © 2020-2023  润新知