Chinaunix首页 | 论坛 | 博客
  • 博客访问: 71298
  • 博文数量: 27
  • 博客积分: 2015
  • 博客等级: 大尉
  • 技术积分: 300
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-18 19:36
文章分类

全部博文(27)

文章存档

2011年(1)

2010年(5)

2009年(16)

2008年(5)

我的朋友

分类: C/C++

2010-06-08 16:48:49

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string time = System.DateTime.Now.ToShortTimeString();
            string text = textBox1.Text;
            string sss = System.DateTime.Now.ToShortDateString() + ".txt";
            sss = "d:\\" + sss;
            File.Delete(sss);
            FileStream fst = new FileStream(sss, FileMode.Append);
            //写数据到a.txt格式
            StreamWriter swt = new StreamWriter(fst, System.Text.Encoding.GetEncoding("utf-8"));
            //写入
            swt.WriteLine(time + '\r' + "写" + text);
            swt.Close();
            fst.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string ss = System.DateTime.Now.ToShortDateString() + ".txt";
            ss = "d:\\" + ss;
            //FileStream fs = new FileStream(sss,
            try
            {
                StreamReader srt = new StreamReader(ss, Convert.ToBoolean(FileMode.Open));
                //存在
                textBox2.Text = srt.ReadToEnd();

                srt.Close();

            }
            catch (FileNotFoundException ee)
            {
                textBox2.Text = ee.ToString();
            }
        }
    }
}

 

 

//删除文件 FileInfo fi=new FileInfo("a.txt");

//fi.Delete();

阅读(410) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~