zoukankan      html  css  js  c++  java
  • 文件打开保存

      /// <summary>
            /// 打开文件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnFile_Click(object sender, EventArgs e)
            {
                using (OpenFileDialog openFile = new OpenFileDialog())
                {
    openFile.Filter = "文本文档|*.txt|All files (*.*)|*.*"; if (openFile.ShowDialog() != DialogResult.OK) { return; } using (FileStream fileStream = new FileStream(openFile.FileName, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader(fileStream)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); this.txtContent.Text = line; } } } } } /// <summary> /// 保存文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveFile_Click(object sender, EventArgs e) {   using (SaveFileDialog saveFile = new SaveFileDialog()) {
    saveFile.Filter = "文本文档|*.txt|All files (*.*)|*.*"; if (saveFile.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } using (FileStream fs = new FileStream(saveFile.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { //using (StreamWriter sw = new StreamWriter(fs)) //{ // sw.Write(txtContent.Text); // sw.Flush(); //} string str= txtContent.Text; byte[] result = Encoding.Default.GetBytes(str); fs.Write(result, 0, result.Length); fs.Flush(); } } }

      

  • 相关阅读:
    Autofac(01)
    深入理解ADO.NET Entity Framework(02)
    使用excel 数据透视表画图
    C# 控制CH341进行SPI,I2C读写
    C# winform使用combobox遍历文件夹内所有文件
    通用分页存储过程
    如何让你的SQL运行得更快
    sql优化之使用索引
    SQL优化
    SQL 循环语句几种写法
  • 原文地址:https://www.cnblogs.com/haimingkaifa/p/5332569.html
Copyright © 2011-2022 走看看