当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.Read方法代码示例

本文整理汇总了C#中System.IO.StreamReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.Read方法的具体用法?C# StreamReader.Read怎么用?C# StreamReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamReader的用法示例。


在下文中一共展示了StreamReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Post_RSA_Json

        /// <summary>
        /// post方法传递json数据
        /// </summary>
        /// <param name="urlStr">目标url</param>
        /// <param name="urlStrFunc">对应方法</param>
        /// <param name="urlStrPara">json参数</param>
        /// <returns></returns>
        public static string Post_RSA_Json(string urlStr, string urlStrFunc, string urlStrPara)
        {
            Encoding encode = Encoding.UTF8;
            byte[] arrB = encode.GetBytes(urlStrPara);
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(urlStr + urlStrFunc);
            myReq.Method = "POST";
            myReq.ContentType = "application/x-www-form-urlencoded";
            myReq.ContentLength = arrB.Length;
            Stream outStream = myReq.GetRequestStream();
            outStream.Write(arrB, 0, arrB.Length);
            outStream.Close();
            //接收HTTP做出的响应
            WebResponse myResp = myReq.GetResponse();

            Stream ReceiveStream = myResp.GetResponseStream();
            StreamReader readStream = new StreamReader(ReceiveStream, encode);
            Char[] read = new Char[256];
            int count = readStream.Read(read, 0, 256);
            string str = null;
            while (count > 0)
            {
                str += new String(read, 0, count);
                count = readStream.Read(read, 0, 256);
            }
            readStream.Close();
            myResp.Close();
            return str;
        }
开发者ID:aaron-clark-aic,项目名称:WebApplication_Collection,代码行数:35,代码来源:RSAModel.cs

示例2: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string memo = "";
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.cmono.net/?post=504");

                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

                Stream receiveStream = myHttpWebResponse.GetResponseStream();
                Encoding encode = Encoding.GetEncoding("utf-8");
                StreamReader sr = new StreamReader(receiveStream, encode);
                char[] read  = new char[256];
                int count = sr.Read(read, 0, 256);
                while (count>0)
                {
                    string str = new string(read, 0, count);
                    memo += str;
                    count = sr.Read(read, 0, 256);

                }
                sr.Close();
                myHttpWebResponse.Close();
                this.textBox1.Text = memo;
                Regex reg = new Regex(@"<div.+class=context?>(?<content>.+?)</div>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
                string val = reg.Match(memo).Groups["content"].Value;
                MessageBox.Show(val);

            }
            catch (Exception ex)
            {

            }
        }
开发者ID:changweihua,项目名称:VS2012.FormSolution,代码行数:34,代码来源:Form1.cs

示例3: ConvertToString

        /// <summary>
        /// 将Stream 转化成 string
        /// </summary>
        /// <param name="stream">流</param>
        public static string ConvertToString(Stream stream)
        {
            #region

            string strResult = "";
            StreamReader sr = new StreamReader(stream, Encoding.UTF8);

            Char[] read = new Char[256];
            // Read 256 charcters at a time.
            int count = sr.Read(read, 0, 256);

            while (count > 0)
            {
                // Dump the 256 characters on a string and display the string onto the console.
                string str = new String(read, 0, count);
                strResult += str;
                count = sr.Read(read, 0, 256);
            }

            // 释放资源
            sr.Close();
            //sr.Dispose();
            return strResult;

            #endregion
        }
开发者ID:zdx2015,项目名称:Zeniths,代码行数:30,代码来源:FileHelper.cs

示例4: PersistMessage

 /// <summary>
 /// Helper class to persist BizTalk message bodies
 /// </summary>
 /// <param name='message'>The BizTalk message to persist</param>
 /// <param name='destination'>The destination directory to persist the file to</param>
 public static void PersistMessage(IBaseMessage message, string destination)
 {
     using (var fs = new FileStream(destination, FileMode.Create))
     {
         var enc = Encoding.GetEncoding("UTF-8");
         if (!string.IsNullOrEmpty(message.BodyPart.Charset))
         {
             enc = Encoding.GetEncoding(message.BodyPart.Charset);
         }
         using (var writer = new StreamWriter(fs, enc))
         {
             var msgStream = message.BodyPart.GetOriginalDataStream();
             using (var reader = new StreamReader(msgStream, enc))
             {
                 const int size = 1024;
                 var buf = new char[size];
                 var charsRead = reader.Read(buf, 0, size);
                 while (charsRead > 0)
                 {
                     writer.Write(buf, 0, charsRead);
                     charsRead = reader.Read(buf, 0, size);
                 }
             }
         }
     }
 }
开发者ID:RobBowman,项目名称:BizUnit,代码行数:31,代码来源:PersistMessageHelper.cs

示例5: Main

        static void Main()
        {
            using (StreamReader reader = new StreamReader(@"..\..\XML.txt"))
            {
                int i = reader.Read();
                while (i != -1)
                {
                    if (i == '>')
                    {
                        string text = String.Empty;

                        while ((i = reader.Read()) != -1 && i != '<')
                        {
                            text += (char)i;
                        }

                        if (!String.IsNullOrWhiteSpace(text))
                        {
                            Console.WriteLine(text.Trim());
                        }
                    }
                    i = reader.Read();
                }

            }
        }
开发者ID:peterlambov,项目名称:CSharp,代码行数:26,代码来源:Delete.cs

示例6: CheckSourceFileForBadCharacters

        /// <summary>
        /// Check an ASCII encoded file for the presence of bad characters
        /// and character combinations.  What we consider bad:
        ///  - Tab characters.
        ///  - Carraige returns not followed by a line feed.
        ///  - Line feeds not preceeded by a carraige return.
        /// </summary>
        /// <param name="sourcePath">File to check.</param>
        /// <returns>True if no bad characters found.  False otherwise.</returns>
        public static bool CheckSourceFileForBadCharacters(string sourcePath)
        {
            const int HT = 0x09;  // Horizontal tab.
            const int LF = 0x0a;  // Line feed.
            const int CR = 0x0d;  // Carraige return.

            using (StreamReader reader = new StreamReader(sourcePath))
            {
                int octet;

                // REVIEW: Sanity check reader.CurrentEncoding here?
                while ((octet = reader.Read()) > 0)
                {
                    switch (octet)
                    {
                        case CR:
                            if (reader.Read() != LF)
                            {
                                return false;
                            }

                            break;

                        case LF:
                        case HT:
                            return false;
                    }
                }
            }

            return true;
        }
开发者ID:jango2015,项目名称:Ironclad,代码行数:41,代码来源:Util.cs

示例7: ProcessDigit

        public static String ProcessDigit(int FirstCharactor, StreamReader DataStream)
        {
            StringBuilder theNumber = new StringBuilder();
            theNumber.Append((char)FirstCharactor);
            int peekedChar;
            //43 + 45 - 46 .
            while (((peekedChar = DataStream.Peek()) >= 48 && peekedChar <= 57)
                || peekedChar == 46)
            {
                theNumber.Append((char)DataStream.Read());
            }

            if (peekedChar == 69) // E
            {
                theNumber.Append((char)DataStream.Read());
                if ((peekedChar = DataStream.Peek()) == 43 || peekedChar == 45)
                {
                    theNumber.Append((char)DataStream.Read());
                }
                while ((peekedChar = DataStream.Peek()) >= 48 && peekedChar <= 57)
                {
                    theNumber.Append((char)DataStream.Read());
                }
            }
            return theNumber.ToString();
            //Console.WriteLine(theNumber);
        }
开发者ID:JackTing,项目名称:ifctoolkit,代码行数:27,代码来源:Lexer.cs

示例8: displayHttpWebReponse

 /// <summary>
 /// Outputs the HTTP reponse to the console
 /// 
 /// Code taken from http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx
 /// </summary>
 /// <param name="response"></param>       
 private static void displayHttpWebReponse(HttpWebResponse response)
 {
     Console.WriteLine(response.StatusCode);
     Stream receiveStream = response.GetResponseStream();
     Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
     // Pipes the stream to a higher level stream reader with the required encoding format.
     StreamReader readStream = new StreamReader(receiveStream, encode);
     Console.WriteLine("\r\nResponse stream received.");
     Char[] read = new Char[256];
     // Reads 256 characters at a time.
     int count = readStream.Read(read, 0, 256);
     Console.WriteLine("HTML...\r\n");
     while (count > 0)
     {
         // Dumps the 256 characters on a string and displays the string to the console.
         String str = new String(read, 0, count);
         Console.Write(str);
         count = readStream.Read(read, 0, 256);
     }
     Console.WriteLine("");
     // Releases the resources of the response.
     response.Close();
     // Releases the resources of the Stream.
     readStream.Close();
 }
开发者ID:fatman2021,项目名称:piwik-dotnet-tracker,代码行数:31,代码来源:PiwikTrackerSamples.cs

示例9: Parse

        public INode Parse(StreamReader reader)
        {
            HtmlToken token = ConsumeTagToken(reader);
            if (token == HtmlToken.OpenMetaTag)
            {
                CommentParser commentParser = new CommentParser();
                string comment = commentParser.ParseCommentText(reader);
            }
            else if (token == HtmlToken.OpenComment)
            {
                CommentParser commentParser = new CommentParser();
                string comment = commentParser.ParseCommentText(reader);
            }
            else if (token == HtmlToken.OpenTag)
            {
                ConsumeTagName(reader);
            }

            int c = reader.Read();
            while (c > -1)
            {
                if (c == '>')
                {
                }
                c = reader.Read();
            }
            return null;
        }
开发者ID:itaibh,项目名称:WebEngineSharp,代码行数:28,代码来源:NodeParser.cs

示例10: GetPage

        public static string GetPage(string url,int tryTimes = 1)
        {
            string content = "";
            try
            {
                HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create(url);
                myHttpWebRequest1.KeepAlive = false;
                HttpWebResponse myHttpWebResponse1;

                myHttpWebResponse1 = (HttpWebResponse)myHttpWebRequest1.GetResponse();
                System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
                Stream streamResponse = myHttpWebResponse1.GetResponseStream();
                StreamReader streamRead = new StreamReader(streamResponse, utf8);
                Char[] readBuff = new Char[256];
                int count = streamRead.Read(readBuff, 0, 256);
                while (count > 0)
                {
                    String outputData = new String(readBuff, 0, count);
                    content += outputData;
                    count = streamRead.Read(readBuff, 0, 256);
                }
                myHttpWebResponse1.Close();
            }
            catch
            {
                tryTimes++;
                if (tryTimes <= 3)
                    content = GetPage(url, tryTimes);
            }
            return (content);
        }
开发者ID:shaohaiou,项目名称:comopp,代码行数:31,代码来源:Http.cs

示例11: ReadFile

        public static List<string> ReadFile(string filename)
        {
            List<string> listFileContent = new List<string>();

            StringBuilder stringBuilder = new StringBuilder();
            using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader streamReader = new StreamReader(fileStream))
                {
                    char[] fileContents = new char[_bufferSize];
                    int charsRead = streamReader.Read(fileContents, 0, _bufferSize);

                    // Can't do much with 0 bytes
                    //if (charsRead == 0)
                    //    throw new Exception("File is 0 bytes");

                    while (charsRead > 0)
                    {
                        stringBuilder.Append(fileContents);
                        charsRead = streamReader.Read(fileContents, 0, _bufferSize);
                    }

                    string[] contentArray = stringBuilder.ToString().Split(new char[] { '\r', '\n' });
                    foreach (string line in contentArray)
                    {
                        listFileContent.Add(line.Replace("#", ""));
                    }
                    listFileContent.RemoveAll(s => string.IsNullOrEmpty(s));
                }
            }
            return listFileContent;
        }
开发者ID:prog-moh,项目名称:twtboard,代码行数:32,代码来源:GlobusFileHelper.cs

示例12: parseGrilles

 private void parseGrilles()
 {
     string line;
     StreamReader file = new StreamReader(pathFile);
     while ((line = file.ReadLine()) != null)
     {
         string nom = file.ReadLine();
         string date = file.ReadLine();
         string symboles = file.ReadLine();
         int longueur = symboles.Length;
         Grille grille = new Grille(nom, date, symboles, longueur);
         for (int i = 0; i < longueur; i++)
         {
             grille.Cases[i] = new Case[longueur];
             for (int j = 0; j < longueur; j++)
             {
                 grille.Cases[i][j] = new Case();
                 grille.Cases[i][j].Valeur = (char)file.Read();
                 grille.Cases[i][j].Row = i;
                 grille.Cases[i][j].Column = j;
             }
             char tabulation = (char)file.Read();
             char sautDeLigne = (char)file.Read();
         }
         if ((grille.Longueur == 9 || grille.Longueur == 16 || grille.Longueur == 25) && grille.EstValide())
         {
             grilles.Add(grille);
         }
     }
     file.Close();
 }
开发者ID:lienafalionel,项目名称:Sudoku_graphique,代码行数:31,代码来源:SudokusViewModel.cs

示例13: ParseValues

        public static Dictionary<string, object> ParseValues(StreamReader reader, Dictionary<string, object> values)
        {
            char ch;

            do
            {
                do
                {
                    ch = (char)reader.Read();
                } while (whitespace.Contains(ch));

                if (ch == '"')
                {
                    string key = parseString(reader);
                    do
                    {
                        ch = (char)reader.Read();
                    } while (whitespace.Contains(ch));

                    if (ch == '"')
                    {
                        values.Add(key, parseString(reader));
                    }
                    else if (ch == '{')
                    {
                        values.Add(key, ParseValues(reader, new Dictionary<string, object>()));
                    }
                }
            }  while (ch != '}' && !reader.EndOfStream);

            return values;
        }
开发者ID:darkelink,项目名称:Steam-Shortcut-Creator,代码行数:32,代码来源:KeyValues.cs

示例14: POST

 private static string POST(string Url, string Data)
 {
     WebRequest req = WebRequest.Create(Url);
     req.Method = "POST";
     req.Timeout = 100000;
     req.ContentType = "application/x-www-form-urlencoded";
     byte[] sentData = Encoding.GetEncoding(1251).GetBytes(Data);
     req.ContentLength = sentData.Length;
     Stream sendStream = req.GetRequestStream();
     sendStream.Write(sentData, 0, sentData.Length);
     sendStream.Close();
     WebResponse res = req.GetResponse();
     Stream ReceiveStream = res.GetResponseStream();
     StreamReader sr = new StreamReader(ReceiveStream, Encoding.UTF8);
     //Кодировка указывается в зависимости от кодировки ответа сервера
     Char[] read = new Char[256];
     int count = sr.Read(read, 0, 256);
     string Out = String.Empty;
     while (count > 0)
     {
         String str = new String(read, 0, count);
         Out += str;
         count = sr.Read(read, 0, 256);
     }
     return Out;
 }
开发者ID:MrSyabro,项目名称:SyabroCraft,代码行数:26,代码来源:MainWindows.cs

示例15: PostModel

        public static string PostModel(string url, string param, Encoding encoding,int timeout)
        {
            Encoding encode = encoding;
            byte[] arrB = encode.GetBytes(param);
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
            if (timeout > 0) myReq.Timeout = timeout;
            myReq.Method = "POST";
            myReq.ContentType = "application/x-www-form-urlencoded";
            myReq.ContentLength = arrB.Length;
            Stream outStream = myReq.GetRequestStream();
            outStream.Write(arrB, 0, arrB.Length);
            outStream.Close();
            WebResponse myResp = null;
            try
            {
                myResp = myReq.GetResponse();
            }
            catch
            {

            }
            Stream ReceiveStream = myResp.GetResponseStream();
            StreamReader readStream = new StreamReader(ReceiveStream, encode);
            Char[] read = new Char[256];
            int count = readStream.Read(read, 0, 256);
            string str = null;
            while (count > 0)
            {
                str += new String(read, 0, count);
                count = readStream.Read(read, 0, 256);
            }
            readStream.Close();
            myResp.Close();
            return str;
        }
开发者ID:gettogether,项目名称:common-object,代码行数:35,代码来源:RequestHelper.cs


注:本文中的System.IO.StreamReader.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。