streamReader& StreamWriter的理解 [英] streamReader & StreamWriter understanding
问题描述
我很头疼了解streamReader和streamWriter
关系。
我知道如何独立使用streamreader和streamwriter。
但你如何使用streamwriter写出来,你读了什么
streamReader?还有人可以解释他们如何用简单的方式工作
-
矩阵起义
Hi, I have got a major headache understanding streamReader and streamWriter
relationship.
I know how to use the streamreader and streamwriter independently.
but how do you write out using the streamwriter, what you have read into a
streamReader? and also can someone explain how they work in simple terms
--
The Matrix Insurrection
推荐答案
ShadowOfTheBeast< Sh ************** @ discussion.microsoft.com>写道:
ShadowOfTheBeast <Sh**************@discussions.microsoft.com> wrote:
我有一个头疼的了解streamReader和streamWriter
的关系。
我知道如何独立使用streamreader和streamwriter。
但是怎么做你用streamwriter写的,你读到了什么?还有人可以用简单的术语解释它们是如何工作的
Hi, I have got a major headache understanding streamReader and streamWriter
relationship.
I know how to use the streamreader and streamwriter independently.
but how do you write out using the streamwriter, what you have read into a
streamReader? and also can someone explain how they work in simple terms
我不完全确定你的意思。你能给出一个具体的例子吗?
通常你只会这样做:
字符串行;
而( (line = reader.ReadLine())!= null)
{
writer.WriteLine(line);
}
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该群组,请不要给我发邮件也好
I''m not entirely sure what you mean. Could you give a concrete example?
Usually you''d just do something like:
string line;
while ( (line = reader.ReadLine()) != null)
{
writer.WriteLine (line);
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
嗨Jon,
感谢回复我...这是我的代码的一部分
i有一个编写器,它将我的字符串(stringbuilder)写入一个流
和一个从流中获取响应的streamreader,现在问题是我b $ b有
读取流并使用代码中的行打印出来:
Console.WriteLine(sr.ReadToEnd());
>
如何将文本写入文件......我似乎无法实现这一点ou将
看到我有一个测试代码,我一直试图用它来做这个
通常它可能会起作用,如果它只是读取和写入froma文件但是
streamreader正在获取一个httpResponseStream ...但即使这样它也会使用console.writeline打印出
,如上所示和代码中但当我使用另一个
$时b $ b streamwriter尝试将文本写入文件但它不起作用...但是如果我使用相同的新流编写器来编写任意文本它可以作为
在我的测试代码区域中演示并再次在下面:
//fileWriter.Write(sr.ReadToEnd()); //这条线不能工作
fileWriter.Write(这很烦人); //但是这条线路工作..WHY ??
ps一些代码需要取消注释才能使测试代码工作
StreamWriter sw = new StreamWriter(httpRequest.GetRequestStream());
sw.Write(sbuilder。 ToString());
sw.Close();
HttpWebResponse httpResponse =(HttpWebResponse)httpRequest.GetResponse();
StreamReader sr = new StreamReader(httpResponse.GetResponseStream());
Console.WriteLine(sr.ReadToEnd());
/ //测试代码区
///写文件
//////////////////////// //////////////////////////////////////////////// <无线电通信/>
StreamWriter fileWriter = new StreamWriter(" OutputTestfile.txt");
////////////////// ////////////////////////////////////////////////// /
///写入流对象
///////////////////////// /////////////////////// ////////////////////////
// fileWriter.Write(sr.ReadToEnd()); //这条线路不工作
fileWriter.Write(这很烦人); //但是这条线路工作..WHY ??
//// ////////////////////////////////////////////////// //////////////////
/// close stream
/////////// ////////////////////////////////////////////////// //////////
fileWriter.Close();
////////////////// ////////////////////////////////////////////////// ///
///结束测试代码区
sr.Close();
httpResponse。关闭();
谢谢
" Jon Skeet [C#MVP]"写道:
hi Jon,
thanks for replying me...this is part of my code
i have a streamwriter that writes my string (stringbuilder) into a stream
and a streamreader that gets the response from the stream now the problem i
have is
after reading the stream and printing it out using the line in the code:
Console.WriteLine( sr.ReadToEnd() );
how do i write the text to a file..i cant seem to achieve that as you will
see i have a test code below which i have been trying to use to do this
normally it might work if it was just reading and writing froma file but the
streamreader is getting a httpResponseStream...but even then it prints out
using console.writeline as displayed above and in code but when i use another
streamwriter to try and write the text to a file it does not work ...but if i
use the same new stream writer to write an arbitrary text it works as
demonstrated in my test code area and again below:
//fileWriter.Write(sr.ReadToEnd()); //THIS LINE DOES NOT WORK
fileWriter.Write("this is annoying");//BUT THIS LINE WORKS..WHY??
p.s some code needs uncommenting for the test code to work
StreamWriter sw = new StreamWriter( httpRequest.GetRequestStream() );
sw.Write( sbuilder.ToString() );
sw.Close();
HttpWebResponse httpResponse = ( HttpWebResponse )httpRequest.GetResponse( );
StreamReader sr = new StreamReader( httpResponse.GetResponseStream() );
Console.WriteLine( sr.ReadToEnd() );
///Test code area
///write file
////////////////////////////////////////////////////////////////////////
StreamWriter fileWriter = new StreamWriter("OutputTestfile.txt");
/////////////////////////////////////////////////////////////////////
///write to the stream object
////////////////////////////////////////////////////////////////////////
//fileWriter.Write(sr.ReadToEnd()); //THIS LINE DOES NOT WORK
fileWriter.Write("this is annoying");//BUT THIS LINE WORKS..WHY??
////////////////////////////////////////////////////////////////////////
///close stream
///////////////////////////////////////////////////////////////////////
fileWriter.Close();
///////////////////////////////////////////////////////////////////////
/// end test code area
sr.Close();
httpResponse.Close();
thanks
"Jon Skeet [C# MVP]" wrote:
ShadowOfTheBeast< Sh ************** @ discussion.microsoft.com>写道:
ShadowOfTheBeast <Sh**************@discussions.microsoft.com> wrote:
我有一个头疼的了解streamReader和streamWriter
的关系。
我知道如何独立使用streamreader和streamwriter。
但是怎么做你用streamwriter写的,你读到了什么?还有人可以用简单的术语解释它们是如何工作的
Hi, I have got a major headache understanding streamReader and streamWriter
relationship.
I know how to use the streamreader and streamwriter independently.
but how do you write out using the streamwriter, what you have read into a
streamReader? and also can someone explain how they work in simple terms
我不完全确定你的意思。你能给出一个具体的例子吗?
通常你会做的事情如下:
字符串行;
while((line = reader.ReadLine())!= null )
{
author.WriteLine(line);
}
- Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet <如果回复小组,请不要给我发邮件
I''m not entirely sure what you mean. Could you give a concrete example?
Usually you''d just do something like:
string line;
while ( (line = reader.ReadLine()) != null)
{
writer.WriteLine (line);
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
ShadowOfTheBeast< Sh ************ **@discussions.microsoft.com>写道:
ShadowOfTheBeast <Sh**************@discussions.microsoft.com> wrote:
感谢回复我...这是我的代码的一部分
我有一个将我的字符串(stringbuilder)写入流中的编写器
一个流读取器,从流中获取响应,现在问题是
在读完流并使用代码中的行打印出来之后:
Console.WriteLine( sr.ReadToEnd());
thanks for replying me...this is part of my code
i have a streamwriter that writes my string (stringbuilder) into a stream
and a streamreader that gets the response from the stream now the problem i
have is
after reading the stream and printing it out using the line in the code:
Console.WriteLine( sr.ReadToEnd() );
如果可行,那么简单的StreamWriter.Write也可以正常工作。
你能发一个简短但完整的程序来演示
问题吗?
见 http://www.pobox.com/~skeet/csharp/complete.html 了解详情
我的意思是什么。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该组,请不要给我发邮件
If that works, then a simple StreamWriter.Write should work fine too.
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
If replying to the group, please do not mail me too
这篇关于streamReader& StreamWriter的理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!