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)
            {

            }

        }
    }

  • 相关阅读:
    最短路径之spfa
    最短路径之Bellman-Ford——解决负权边
    最短路径之Floyd-Warshall算法
    图上最短路径问题
    它们其实都是图(二分图)
    记忆化结果再利用 进一步探讨递推关系
    leetcode 376. 摆动序列 java
    leetcode 368. 最大整除子集 java
    leetcode 96. 不同的二叉搜索树 java
    leetcode 454. 四数相加 II java
  • 原文地址:https://www.cnblogs.com/softimagewht/p/2235247.html
Copyright © 2011-2022 走看看