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


C# System.IO.StreamReader.ReadBlock方法代码示例

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


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

示例1: ReadFile

    void ReadFile(int index)
    {
        // To run this code, substitute a valid path from your local machine
            string path = @"c:\users\public\test.txt";
            System.IO.StreamReader file = new System.IO.StreamReader(path);
            char[] buffer = new char[10];
            try
            {
                file.ReadBlock(buffer, index, buffer.Length);
            }
            catch (System.IO.IOException e)
            {
                Console.WriteLine("Error reading from {0}. Message = {1}", path, e.Message);
            }

            finally
            {
                if (file != null)
                {
                    file.Close();
                }
            }
            // Do something with buffer...
    }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:24,代码来源:try-catch-finally--csharp-reference-_1.cs

示例2: DetectStreamEncoding

        public static Encoding DetectStreamEncoding(System.IO.Stream stream)
        {
            var reader = new System.IO.StreamReader(stream, true);
            var buffer = new char[256];

            reader.ReadBlock(buffer, 0, (int)Math.Min(buffer.Length, stream.Length));
            var result = reader.CurrentEncoding;

            stream.Seek(0, System.IO.SeekOrigin.Begin);
            return result;
        }
开发者ID:sq,项目名称:Fracture,代码行数:11,代码来源:IO.cs

示例3: Main


//.........这里部分代码省略.........
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + "");
                    outFile.WriteLine ("Errc: " + "");
                    outFile.WriteLine ("Exce: " + GetException (exc));
                }
            } catch (Exception) {
            }

            try {
                char[] array = new char[1];
                array[0] = 'a';
                System.IO.TextReader tr = new System.IO.StreamReader (tempPath + "\\dummyFile13.txt");
                try {
                    exc = null;
                    s = null;
                    now = System.DateTime.Now;
                    s = tr.ReadLine ();
                } catch (Exception e) {
                    exc = e;
                } finally {
                    outFile.WriteLine ("Name: " + tempPath + "\\dummyFile13.txt");
                    outFile.WriteLine ("Func: " + "System.IO.TextReader.ReadLine()");
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + toString (s));
                    outFile.WriteLine ("Errc: " + "");
                    outFile.WriteLine ("Exce: " + GetException (exc));
                }
                try {
                    exc = null;
                    i = 0;
                    now = System.DateTime.Now;
                    i = tr.ReadBlock (array, 0, 1);
                } catch (Exception e) {
                    exc = e;
                } finally {
                    outFile.WriteLine ("Name: " + tempPath + "\\dummyFile13.txt");
                    outFile.WriteLine ("Func: " + "System.IO.TextReader.ReadBlock(Char[], Int32, Int32)");
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + toString (i));
                    outFile.WriteLine ("Errc: " + "");
                    outFile.WriteLine ("Exce: " + GetException (exc));
                }
                try {
                    exc = null;
                    i = 0;
                    now = System.DateTime.Now;
                    i = tr.Read ();
                } catch (Exception e) {
                    exc = e;
                } finally {
                    outFile.WriteLine ("Name: " + tempPath + "\\dummyFile13.txt");
                    outFile.WriteLine ("Func: " + "System.IO.TextReader.Read()");
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + toString (i));
                    outFile.WriteLine ("Errc: " + "");
                    outFile.WriteLine ("Exce: " + GetException (exc));
                }
                try {
                    exc = null;
                    i = 0;
                    now = System.DateTime.Now;
                    i = tr.Read (array, 0, 1);
开发者ID:uvbs,项目名称:Holodeck,代码行数:67,代码来源:TestApplication4.cs


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