zoukankan      html  css  js  c++  java
  • StreamWriter、StreamReader

    IO流操作文件内容,using System.IO;//引入命名空间

            private void button1_Click(object sender, EventArgs e)
            {
                if (textBox1.Text==string.Empty)
                {
                    MessageBox.Show("写入内容不能为空");
                }
                else
                {
                    saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";//打开保存文件对话框
                    if (saveFileDialog1.ShowDialog()==DialogResult.OK)//单机OK按钮
                    {
                        StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, true);//创建写入流
                        sw.WriteLine(textBox1.Text);//写入
                        sw.Close();//关闭流
                    }
                }
            }
            private void button2_Click(object sender, EventArgs e)
            {
                openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
                if (openFileDialog1.ShowDialog()==DialogResult.OK)
                {
                    StreamReader sr = new StreamReader(openFileDialog1.FileName);//创建读出流
                    textBox1.Text = sr.ReadToEnd();//读出全部内容
                    sr.Close();//关闭流
                }
            }
  • 相关阅读:
    fidller 打断点
    随笔
    HTML标签介绍
    补充9.27----9.28
    html5_______9.26
    9.14
    9.13笔记
    9.12笔记
    CSS样式的引用
    html5_______9.10
  • 原文地址:https://www.cnblogs.com/xixixing/p/10822961.html
Copyright © 2011-2022 走看看