zoukankan      html  css  js  c++  java
  • c#中对文件的操作小结(http://www.a2605.org/ddvipcom/program/c/index1/134.htm)

    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");
       }
      }
  • 相关阅读:
    hdu 4403 枚举
    hdu 4405概率dp
    lightoj 1036 dp
    lightoj 1033 区间dp
    lightoj 1032 二进制的dp
    hdu 4293 dp求最大权值不重合区间
    poj 2449 第k短路
    hdu 4284 状态压缩
    hdu4281 区间dp
    poj 2288 tsp经典问题
  • 原文地址:https://www.cnblogs.com/snowball/p/442018.html
Copyright © 2011-2022 走看看