zoukankan      html  css  js  c++  java
  • C#读写文本文件源码片段

    下边内容段是关于C#读写文本文件片段的内容,应该是对码农们也有用。

    using System;
    using System.IO;
    public class TestReadFile
    {
    public static void Main(String[] args)
    {
    FileStream fs = new FileStream(@c:temptest.txt , FileMode.Open, FileAccess.Read);
    StreamReader sr = new StreamReader(fs);

    String line=sr.ReadLine();
    while (line!=null)
    {
    Console.WriteLine(line);
    line=sr.ReadLine();
    }

    sr.Close();
    fs.Close();
    }
    }





    写文本文件代码片段



    using System;
    using System.IO;
    public class TestWriteFile
    {
    public static void Main(String[] args)
    {
    FileStream fs = new FileStream(@c:temptest.txt , FileMode.OpenOrCreate, FileAccess.Write);
    StreamWriter sw = new StreamWriter(fs);
    sw.BaseStream.Seek(0, SeekOrigin.End);
    sw.WriteLine( First Line );
    sw.WriteLine( Second Line);
    sw.Flush();
    }

  • 相关阅读:
    5.14事务
    5.13Mysql数据库Database
    未来打算
    浅谈P NP NPC
    1222
    1219
    Linux初等命令
    惩罚因子(penalty term)与损失函数(loss function)
    12 14
    java 泛型思考
  • 原文地址:https://www.cnblogs.com/codeoldman/p/13093576.html
Copyright © 2011-2022 走看看