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");
       }
      }
  • 相关阅读:
    ubuntu16.04下vim安装失败
    Sql Server函数全解(三)数据类型转换函数和文本图像函数
    Sql Server函数全解(二)数学函数
    Sql server 2008 中varbinary查询
    处理乱码问题
    快速排序
    《Java编程思想》笔记 第二章 一切都是对象
    1021: 组合数末尾的零
    11462
    The Bus Driver Problem
  • 原文地址:https://www.cnblogs.com/snowball/p/442018.html
Copyright © 2011-2022 走看看