简体   繁体   English

Windows Server 2008上未创建换行符

[英]newline not created on Windows Server 2008

I'm working in C# on a development machine (Windows 8) and using the following code to append a line to a file: 我正在开发计算机(Windows 8)上使用C#进行工作,并使用以下代码在文件中附加一行:

using (System.IO.StreamWriter fs = new System.IO.StreamWriter(sFileName, true))
{
    fs.WriteLine(sLine);
}

This works perfectly fine in my development environment and every time creates a new line. 这在我的开发环境中工作得很好,并且每次都创建新行。 However, when I deploy it to Windows Server 2008, it does not create a new line, it just appends to the existing line so after running several times I have one long line of data. 但是,当我将其部署到Windows Server 2008时,它不会创建新行,而只是追加到现有行上,因此在运行几次之后,我只有一条长数据行。

What happens differently between the two computers? 两台计算机之间会有什么不同? Is there a setting I need to change on my server to get this to work right? 是否需要更改服务器上的设置才能使其正常工作?

Thanks! 谢谢!

Sorry, this should be a comment, but I don't have reputation. 抱歉,这应该是评论,但我没有声誉。

I've got another suggestion, why don't you try using File.WriteLine instead of StreamWriter.WriteLine ? 我还有另一个建议,为什么不尝试使用File.WriteLine代替StreamWriter.WriteLine

public void addText(string stringToAdd, string FilePath)
{
     System.IO.File.WriteAllLines(FilePath, new string[]{stringToAdd});
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM