zoukankan      html  css  js  c++  java
  • C#向文件中追加字符

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text; 
    using System.IO;
    namespace OpeartorFile
    {
        /// <summary>
        /// 范小军
        /// 用来学习向文件中追加字符的方法
        /// </summary>
        class Program
        {
            static void Main(string[] args)
            {
    
                FileInfo fi = new FileInfo(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"SBILog.txt");//创建一个文件信息
                if (fi.Exists && fi.Length > 1024 * 1024)
                {//先判断是否存在改名称的文件,并且判断文件的大小
                    fi.Delete();
                }
                FileStream fs = new FileStream(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"SBILog.txt", FileMode.OpenOrCreate, FileAccess.Write);//创建一个文件流
                StreamWriter m_streamWriter = new StreamWriter(fs);//创建一个文件输入流
                m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);//字符追加的位置
                m_streamWriter.WriteLine("Msg:" + DateTime.Now.ToString() + " -- " + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\n");//向文件中写入字符串
                m_streamWriter.Flush();//清除此流的缓冲区,使得所有缓冲的数据都写入到文件中。
                m_streamWriter.Close();//关闭输入流
                fs.Close();//关闭文件流
            }
        }
    }
    
  • 相关阅读:
    log4j的使用
    转:http与https
    转:归一化与正则化
    转:python 的开源库
    转:openTSDB 2.0 安装
    hadoop 2.2.0编译安装及打包
    查看磁盘信息
    HBase Region的flush过程
    HBase96的RPC
    阐述二维码的原理以及使用google api和PHP QR Code来生成二维码
  • 原文地址:https://www.cnblogs.com/fanxiaojun/p/2428022.html
Copyright © 2011-2022 走看看