StreamWriter丢失了现有文本的格式? [英] StreamWriter loses format of existing text?
问题描述
您好,
我的代码是写入现有文件。但是在我的C#代码
附加文件后,前一个文本丢失了所有的结束字符,
成为一个长行。如何保留已存在的
文本的格式化?
FileStream stream = new FileStream(strFileName,FileMode.Append,
FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(strErrorMessage);
提前感谢您的帮助....
Duckwon
Hello,
My code is suppose to write to an existing file. But after my C# code
appends the file, the previous text loses all the endline characters,
becoming one long line. How can I retain the formating of the pre-existing
text?
FileStream stream = new FileStream(strFileName, FileMode.Append,
FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(strErrorMessage);
Thanks in advancefor any help....
Duckwon
推荐答案
Duckwon< Du ***** @ discussion.microsoft.comwrote:
Duckwon <Du*****@discussions.microsoft.comwrote:
我的代码是写入现有文件。但是在我的C#代码
附加文件后,前一个文本丢失了所有的结束字符,
成为一个长行。如何保留已存在的
文本的格式化?
FileStream stream = new FileStream(strFileName,FileMode.Append,
FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(strErrorMessage);
提前感谢您提供任何帮助....
My code is suppose to write to an existing file. But after my C# code
appends the file, the previous text loses all the endline characters,
becoming one long line. How can I retain the formating of the pre-existing
text?
FileStream stream = new FileStream(strFileName, FileMode.Append,
FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(strErrorMessage);
Thanks in advancefor any help....
你还没有展示你是如何构建strErrorMessage的第一个
地方。
你能发一个简短但完整的程序来演示
问题吗?
请参阅 http://www.pobox。 com / ~siget / csharp / complete.html 了解详情
我的意思是什么。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet
如果回复对于小组,请不要给我发邮件
You haven''t shown how you''re constructing strErrorMessage in the first
place.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
目前它只是一个简单的
字符串strErrorMessage = dCurrentTime.Date + " + dCurrentTime.TimeOfDay +
":" + strFile +",Line" + nLine.ToString()+":" + strError;
strFile和strError也是带有测试文本的字符串,例如Test
包含预先存在文本的文件我试图追加,创建了
,之前用C ++编写。这可能是编码问题吗?如果是这样,
我将如何解决它?
感谢您的帮助
" Jon Skeet [C#MVP]"写道:
At the moment its just a simple
string strErrorMessage = dCurrentTime.Date + " " + dCurrentTime.TimeOfDay +
": " + strFile + ", Line " + nLine.ToString() + ": " + strError;
strFile and strError are also strings with test text such as "Test"
The file with the pre-existing text that I am trying to append, was created
and previously written to in C++. Is this maybe an encoding problem? If so,
how would I go about fixing it?
Thanks for helping
"Jon Skeet [C# MVP]" wrote:
Duckwon< Du ***** @ discussion.microsoft.comwrote:
Duckwon <Du*****@discussions.microsoft.comwrote:
我的代码假设写入现有文件。但是在我的C#代码
附加文件后,前一个文本丢失了所有的结束字符,
成为一个长行。如何保留已存在的
文本的格式化?
FileStream stream = new FileStream(strFileName,FileMode.Append,
FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(strErrorMessage);
在此先感谢任何帮助....
My code is suppose to write to an existing file. But after my C# code
appends the file, the previous text loses all the endline characters,
becoming one long line. How can I retain the formating of the pre-existing
text?
FileStream stream = new FileStream(strFileName, FileMode.Append,
FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(strErrorMessage);
Thanks in advancefor any help....
你还没有展示你是如何构建strErrorMessage的第一个
地方。
你能发一个简短但完整的程序来演示
问题吗?
请参阅 http://www.pobox。 com / ~siget / csharp / complete.html 了解详情
我的意思是什么。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet
如果回复小组,请不要给我发邮件
You haven''t shown how you''re constructing strErrorMessage in the first
place.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Duckwon< Du ***** @ discuss.microsoft.comwrote:
Duckwon <Du*****@discussions.microsoft.comwrote:
目前它只是一个简单的字符串strErrorMessage = dCurrentTime.Date +" " + dCurrentTime.TimeOfDay +
":" + strFile +",Line" + nLine.ToString()+":" + strError;
strFile和strError也是带有测试文本的字符串,例如Test
包含预先存在文本的文件我试图追加,创建了
,之前用C ++编写。这可能是编码问题吗?如果是这样,
我将如何解决它?
At the moment its just a simple
string strErrorMessage = dCurrentTime.Date + " " + dCurrentTime.TimeOfDay +
": " + strFile + ", Line " + nLine.ToString() + ": " + strError;
strFile and strError are also strings with test text such as "Test"
The file with the pre-existing text that I am trying to append, was created
and previously written to in C++. Is this maybe an encoding problem? If so,
how would I go about fixing it?
这很难说。它可能是,或者可能是C ++代码是使用不同的行结束字符串
。
你能用一个样本文件给我发邮件,之前和之后?
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet
如果回复小组,请不要给我发邮件
It''s hard to say. It could be, or it could be that the C++ code is
using a different end of line string.
Could you mail me with a sample file, both before and after?
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
这篇关于StreamWriter丢失了现有文本的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!