【问题标题】:Append line to the file without line break在没有换行符的情况下将行附加到文件
【发布时间】:2011-09-25 20:28:39
【问题描述】:

现在我正在向现有文件添加新行,如下所示:

   using (StreamWriter sw = File.AppendText(TemplateOutput))
   {
      sw.WriteLine(parsedFile);
   }

这样 AppendText 会自动在行尾添加换行符。我怎么能改变它,所以它不会在末尾添加换行符?

【问题讨论】:

    标签: c# streamwriter


    【解决方案1】:

    怎么样

    using (StreamWriter sw = File.AppendText(TemplateOutput))
    {      
    sw.Write(parsedFile);   
    } 
    

    【讨论】:

      【解决方案2】:

      改用StreamWriter.Write 方法。

      【讨论】:

        【解决方案3】:
        using (StreamWriter sw = File.AppendText(TemplateOutput))
           {
              sw.Write(parsedFile);
           }
        

        【讨论】:

          【解决方案4】:

          WriteLine 调用更改为Write

          或者,如果您只是想将一些文本附加到文件中,请使用File.AppendAllText

          File.AppendAllText(TemplateOutput, parsedFile);
          

          不需要做更多的工作:)

          【讨论】:

            猜你喜欢
            • 2014-02-10
            • 2015-11-30
            • 2021-01-20
            • 2012-09-02
            • 1970-01-01
            • 2011-07-09
            • 2021-08-10
            相关资源
            最近更新 更多