关闭

winfrom——文本内容存入流

189人阅读 评论(0) 收藏 举报
分类:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication5
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "文本文件|*.txt|所有文件|*.*";
           DialogResult isok= openFileDialog1.ShowDialog();
        
            if (isok == DialogResult.OK)
            {
                string filename = openFileDialog1.FileName;
                StreamReader sr = new StreamReader(filename,Encoding.Default);
                textBox1.Text = sr.ReadToEnd();
                sr.Close();
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
           DialogResult isok=  saveFileDialog1.ShowDialog();
           if (isok == DialogResult.OK)
           {
               string filename = saveFileDialog1.FileName;
               StreamWriter sw = new StreamWriter(filename);
               sw.Write(textBox1.Text);
               sw.Close();
           }
        }
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2763次
    • 积分:227
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档