zoukankan      html  css  js  c++  java
  • 文件操作

    以下为文件操作的一些语法:

    1:查看磁盘中的文件夹
        string[] dirs = Directory.GetDirectories(@"d:\"); 
            foreach (string dir in dirs)
            {
                 Console.WriteLine(dir);
            }

    2:查看磁盘中的文件
        string[] files = Directory.GetFiles(@"d:\");
            foreach (string file in files)
            {
                 Console.WriteLine(file);
            }

    3:向磁盘中写入文件
             using (FileStream fs = new FileStream(@"e:\file.txt", FileMode.Append, FileAccess.Write))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("向磁盘中写入文件");
                        sw.Flush();
                    }
                }

    4:读取磁盘中的文件
         using (FileStream fs = new FileStream(@"e:\file.txt", FileMode.Open, FileAccess.Read))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        Console.WriteLine(sr.ReadToEnd());
                    }
                }


    谢谢!

  • 相关阅读:
    UVA 11021繁衍模型+概率计算
    LA 5059博弈+SG函数
    LA 3942 字典树
    Beat---hdu2614
    Wooden Sticks---hdu1051(最长上升子序列)
    欧拉函数基础
    1370
    钱币兑换问题---hdu1284(完全背包)
    Drainage Ditches--hdu1532(网络流 模板)
    Fibonacci--poj3070(矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/jeffqing/p/2588960.html
Copyright © 2011-2022 走看看