首页 > 其他 > 详细

C#打开一个文本文件并读写

时间:2014-01-16 00:03:40      阅读:407      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
OpenFileDialog OFD = new OpenFileDialog();
            OFD.Title = "打开第一个文本文件";
            OFD.FileName = "*.txt";
            OFD.InitialDirectory = WorkSpacePath;
            if (OFD.ShowDialog() == DialogResult.OK)
            {
                FileInfo fi = new FileInfo(OFD.FileName);
                StreamReader sr = fi.OpenText();
                while (sr.Peek() > 0)
                {
                    listBox1.Items.Add(sr.ReadLine());
                }
                sr.Close();
                textBox1.Text = OFD.FileName;
                this.statusStrip1.Items[1].Text = listBox1.Items.Count.ToString();
            }
bubuko.com,布布扣

写一个文本文件:

bubuko.com,布布扣
string Path = Application.StartupPath;
            FileStream fs = new FileStream(Path + "\\path.dll", FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(path08);
            sw.WriteLine(path07);
            sw.WriteLine(path06);
            sw.WriteLine(WorkSpacePath);
            sw.WriteLine(EFDCPath);
            sw.WriteLine(path09);
            sw.Close();
            fs.Close();
bubuko.com,布布扣

C#打开一个文本文件并读写

原文:http://www.cnblogs.com/China3S/p/3516517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!