I'm sorry to write in english, because there is no chinese input software in my computer in company.
string s = "asdfghjkl";
Stream stream = new MemoryStream();
StreamWriter sw = new StreamWriter(stream);
sw.WriteLine(s);
StreamReader sr = new StreamReader(stream);
string str = sr.ReadToEnd();
I define a Stream and write something in it .But I can't read anything into the new string, why?
Please reply in Chinese , thanks.
string s = "asdfghjkl";
Stream stream = new MemoryStream();
StreamWriter sw = new StreamWriter(stream);
sw.WriteLine(s);
StreamReader sr = new StreamReader(stream);
string str = sr.ReadToEnd();
I define a Stream and write something in it .But I can't read anything into the new string, why?
Please reply in Chinese , thanks.
string result = reader.ReadToEnd();
DataContractJsonSerializer ser = new DataContractJsonSerializer(Result.type);
object o = ser.ReadObject(responseStream); //this line raise a exceptionAnd if I get out the data with DataContractJsonSerializer first, then the data can be currectly got out and put into the object, next I try to get out the data with streamReader.ReadToEnd() into a string, the string is "",but there is no exception.
The code is : object o = ser.ReadObject(responseStream);
DataContractJsonSerializer ser = new DataContractJsonSerializer(Result.type);
StreamReader reader = new StreamReader(responseStream);
string result = reader.ReadToEnd(); //the result is ""I want to know why the data lose when I get out the data the first time whatever the way I use.
Reply in Chinese, Thanks.
string s = "asdfghjkl";
Stream stream = new MemoryStream();
StreamWriter sw = new StreamWriter(stream);
sw.WriteLine(s);
/////////加上这两句/////////
sw.Flush();
sw.Close;
/////////////////////////
StreamReader sr = new StreamReader(stream);
string str = sr.ReadToEnd();
这个问题很简单啊,从Internet出来的Stream是单向只读的,你第一次读以后读指针就会到流的最后端了,不可能再回来。第二次肯定什么也读不到了。