zoukankan      html  css  js  c++  java
  • c#读取二进制文件 文件结束标志

    FileStream fs = File.OpenRead(path);
    BinaryReader brReader = new BinaryReader(fs);
    
     while (brReader.BaseStream.Position < brReader.BaseStream.Length)
     {
         //TODO
     }
    
     brReader.Close();
                using (BinaryReader br = new BinaryReader(fs))
                {
                    while (br.PeekChar() > -1)
                    {
                        //TODO
                    }
                }

     以上两种方法可以判断文件结束

    下边是简单记录日志时候用的写入到txt文件里的方法

    string logpath = Settings.LogPath;//d:logs
    string logFileName = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
    string logFilePath = logpath + "\" + logFileName;
    string log = DateTime.Now.ToString() + ":  " + e.Message;
      
    if (!File.Exists(logFilePath)) File.Create(logFilePath).Close();
    using (StreamWriter sw = File.AppendText(logFilePath))
    {
        sw.WriteLine("{0}", log);
        sw.Flush();
        sw.Close();
    }
  • 相关阅读:
    nginx
    VSFTPD
    Dubbo
    ZooKeeper
    maven
    linux 学习
    Shiro安全框架
    Jqueryの锋利的jquery练习
    Java中的数组操作进阶
    Java IO总结之缓冲读入文件
  • 原文地址:https://www.cnblogs.com/hbhzz/p/3447134.html
Copyright © 2011-2022 走看看