zoukankan      html  css  js  c++  java
  • C# 文件读取方法,自己写的例子,保存一下,备用

      /// <summary>
            /// 将output.config内容传到app.config
            /// </summary>
            string ReadString;
            //两个地址
            string path1 = @"D:wcfxml文件读写Xml_WirteOrReadXml_WirteOrReadoutput.config";
            string path2 = @"D:wcfxml文件读写Xml_WirteOrReadXml_WirteOrReadapp.config"; /// <summary>
          /// 读文件
          /// </summary>
          /// <param name="path"></param>
            public void ReadFile(string path)
            {
                try
                {
                    FileStream afile = new FileStream(path, FileMode.Open);
                    StreamReader sread = new StreamReader(afile);
                    //ReadString = sread.ReadLine();
                    ReadString = sread.ReadToEnd();               
                    sread.Close();
                    afile.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    
            /// <summary>
            /// 写文件
            /// </summary>
            public void WriteFile()
            {
                try 
                {
                    FileStream afile = new FileStream(path2, FileMode.OpenOrCreate);
                    StreamWriter swrite = new StreamWriter(afile);
                    if (!string.IsNullOrEmpty(ReadString))
                    { 
                        swrite.Write(ReadString);
                       // swrite.WriteLine(ReadString);
                    }                
                    swrite.Close();
                    afile.Close();            
            }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

    C# 对于文件的读取与写入!!个人做的一个小例子!

  • 相关阅读:
    shell数组(产生不同的随机数)
    统计服务连接状况
    子网掩码与子网划分
    oracle 12g sqlplus安装
    MySQL的备份和还原
    mysql日志
    mysql用户和权限管理
    mysql show
    CentOS Linux解决Device eth0 does not seem to be present
    mysqldump命令详解(转载)
  • 原文地址:https://www.cnblogs.com/chcong/p/4303353.html
Copyright © 2011-2022 走看看