文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C#对文件进行读写

C#对文件进行读写

时间:2010-06-08  来源:lijun2087

 

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();

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载