zoukankan      html  css  js  c++  java
  • c# 记录内容到txt文件

    //string记录到文件

    string a= content;//采样结果
    if (!File.Exists("e:\newfile\newtxt.txt"))
    {
    new FileStream(" e:\newfile\newtxt.txt", FileMode.Create, FileAccess.Write);//创建写入文件
    }
    FileStream fs3 = new FileStream("e:\newfile\newtxt.txt", FileMode.Append, FileAccess.Write);
    StreamWriter sw3 = new StreamWriter(fs3);
    sw3.Write(a+ " ");//开始写入值
    sw3.Close();
    fs3.Close();

    //byte[]记录到文件

    /**文件记录 begin*/
    FileStream fs = new FileStream(SettingsUnit.UpdateDataPath, FileMode.Append, FileAccess.Write);
    StreamWriter sw1 = new StreamWriter(fs);
    string filePath = SettingsUnit.UpdateDataPath;
    FileInfo fileInfo = new FileInfo(filePath);
    double FileLength = fileInfo.Length;//取文件长度(字节)
    if (ReturnUpdate1.Start == "0" && FileLength > 10000)
    {
    sw1.Close();
    fs.Close();
    fs = new FileStream(SettingsUnit.UpdateDataPath, FileMode.Truncate, FileAccess.ReadWrite);//清空文件内容
    fs.Close();
    fs = new FileStream(SettingsUnit.UpdateDataPath, FileMode.Append, FileAccess.Write);//重新打开文件
    sw1 = new StreamWriter(fs);
    }
    fs.Write(buffernew, 0, buffernew.Length); //将byte数组写入文件中
    sw1.Close();
    fs.Close();
    /**文件记录 end*/

  • 相关阅读:
    min-max 容斥
    集训作业
    UOJ Test Round 3
    uoj Goodbye Dingyou
    Codeforces Round #516 (Div. 1) 题解
    Codeforces Round #517(Div. 1) 题解
    概率论(Ⅱ)
    Berlekamp-Massey算法学习笔记
    多项式取模优化线性递推总结
    [ZJOI2019]线段树
  • 原文地址:https://www.cnblogs.com/webttt/p/8309580.html
Copyright © 2011-2022 走看看