zoukankan      html  css  js  c++  java
  • 文件写入写出的封装



        #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
  • 相关阅读:
    Java集合框架:Collections工具类
    百度编辑器多图上传返回图片绝对路径问题
    iOS开发中“此证书的签发者无效”的解决方式
    codeblocks如何watch指针
    codeblocks如何watch数组
    printf不支持%lf
    doxygen可以生成C/C++代码的文档(根据注释)
    codeblocks中右键源文件没有Rename选项?
    codeblocks中给GCC编译器加参数
    codeblocks设置当前行高亮
  • 原文地址:https://www.cnblogs.com/wantingqiang/p/1206668.html
Copyright © 2011-2022 走看看