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

            }

        }
    }

  • 相关阅读:
    c# 利用反射设置属性值
    C#中扩展方法
    Python与Ruby比较
    Python 学习笔记(半ZZ半自己写)
    c# 写的一个类帮助器(动态生成类 动态类 动态属性)
    c#学习python
    LBS中从数据库查询某经纬度2KM范围内的数据 针对大数据量的性能优化
    隐藏ToString等系统自带方法
    C#命名规范
    SQL Server 数值四舍五入,小数点后保留2位
  • 原文地址:https://www.cnblogs.com/softimagewht/p/2235247.html
Copyright © 2011-2022 走看看