本文整理汇总了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...
}
示例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;
}
示例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);