zoukankan      html  css  js  c++  java
  • c#的文件流的小范例

    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 wht
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                string path = @"c:\temp\MyTest.txt";
               
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    using (StreamWriter sw = new StreamWriter(path))
                    {
                        sw.WriteLine("This");
                        sw.WriteLine("is some textvbbnvnvncfdh");
                        sw.WriteLine("to test");
                        sw.WriteLine("Reading");
                    }

                    using (StreamReader sr = new StreamReader(path))
                    {
                        string tt = "";
                        while (sr.Peek() >= 0)
                        {
                           // Console.WriteLine(sr.ReadLine());
                           tt += sr.ReadLine() + "\n";
                        }
                        MessageBox.Show(tt);
                    }
                  
            }

            private void listView1_SelectedIndexChanged(object sender, EventArgs e)
            {

            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

        }
    }

  • 相关阅读:
    怎样从外网访问内网MongoDB数据库?
    怎样从外网访问内网MySQL数据库?
    怎样从外网访问内网Tomcat?
    怎样从外网访问内网Oracle数据库?
    怎样从外网访问内网WampServer?
    怎样从外网访问内网Jupyter Notebook?
    怎样从外网访问内网RESTful API?
    怎样从外网访问内网WebSphere?
    系统性能测试步骤
    性能相关面试题
  • 原文地址:https://www.cnblogs.com/softimagewht/p/2235247.html
Copyright © 2011-2022 走看看