zoukankan      html  css  js  c++  java
  • c#中对文件的操作小结

         1、建立一个文本文件
        public class FileClass
        {
         public static void Main()
         {
         WriteToFile();
         }
         static void WriteToFile()
         {
         StreamWriter SW;
         SW=File.CreateText("c:\MyTextFile.txt");
         SW.WriteLine("God is greatest of them all");
         SW.WriteLine("This is second line");
         SW.Close();
         Console.WriteLine("File Created SucacessFully");
         }
        }
        2、读文件
        public class FileClass
        {
         public static void Main()
         {
         ReadFromFile("c:\MyTextFile.txt");
         }
         static void ReadFromFile(string filename)
         {
         StreamReader SR;
         string S;
         SR=File.OpenText(filename);
         S=SR.ReadLine();
         while(S!=null)
         {
         Console.WriteLine(S);
         S=SR.ReadLine();
         }
         SR.Close();
         }
        }
        3、追加操作
        public class FileClass
        {
         public static void Main()
         {
         AppendToFile();
         }
         static void AppendToFile()
         {
         StreamWriter SW;
         SW=File.AppendText("C:\MyTextFile.txt");
         SW.WriteLine("This Line Is Appended");
         SW.Close();
         Console.WriteLine("Text Appended Successfully");
         }
        }

  • 相关阅读:
    apache虚拟主机三种不同配置方式
    搭建http服务器及配置
    学校ftp服务器搭建
    vsftpd搭建使用
    nginx使用
    pxe+kickafkstart (二)转
    pxe批量网络装机
    bash中()使用特性
    ansible使用
    javascript 之 Object.defineProperty
  • 原文地址:https://www.cnblogs.com/hbhbice/p/1714108.html
Copyright © 2011-2022 走看看