zoukankan      html  css  js  c++  java
  • StreamWriter 的应用

       StreamWriter 常用于向文本文件写字符串的, 默认的编码是 utf-8. 在 File.CreateText 方法说明中即有这样的例子:

          string path = @"c:\temp\MyTest.txt";
            if (!File.Exists(path))
            {
                // Create a file to write to.
                using (StreamWriter sw = File.CreateText(path))
                {
                    sw.WriteLine("Hello");
                    sw.WriteLine("And");
                    sw.WriteLine("Welcome");
                }
            }

    流指向开启的文本文件, 常用的方法就是 WriteLine, Write.

    而在其构造函数中, 可以更改编码格式, 如下一种构造函数:

    public StreamWriter(string path, bool append, Encoding encoding);
    这样的一个示例:
    StreamWriter sw = new StreamWriter(@"c:\test.txt", false, Encoding.Unicode);
    sw.WriteLine("写入的一行文本.");
    sw.Flush();
    sw.Close();

    ~做事情贵在坚持~
  • 相关阅读:
    windows加固方案
    redis集群
    tar命令
    nfs安装配置
    nginx php版本隐藏
    细谈select函数(C语言)
    linux 下各errno的意义(转)
    iperf交叉编译:
    主机和虚拟机不能ping通问题
    Linux中tcpdump的编译和使用
  • 原文地址:https://www.cnblogs.com/csMapx/p/2060973.html
Copyright © 2011-2022 走看看