本文整理汇总了C#中StreamReader.ReadBlock方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.ReadBlock方法的具体用法?C# StreamReader.ReadBlock怎么用?C# StreamReader.ReadBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamReader
的用法示例。
在下文中一共展示了StreamReader.ReadBlock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Open_Click
protected void Open_Click(Object sender, EventArgs e)
{
OpenFileDialog o = new OpenFileDialog();
if(o.ShowDialog() == DialogResult.OK) {
Stream file = o.OpenFile();
StreamReader reader = new StreamReader(file);
char[] data = new char[file.Length];
reader.ReadBlock(data,0,(int)file.Length);
text.Text = new String(data);
reader.Close();
}
}
示例2: ReadFile
public void ReadFile(String FileName, int FileSize)
{
char[] buf = new char[FileSize];
StreamReader sr = new StreamReader(new FileStream(FileName, FileMode.Open, FileAccess.Read));
int retval = sr.ReadBlock(buf, 0, FileSize);
file = new String(buf);
// Console.WriteLine(file);
}
示例3: connect
public void connect() {
try {
if (connected) {
throw new SocketIoClientException("already connected");
}
socket = createSocket();
stream = socket.GetStream();
input = new StreamReader(stream);
byte[] bytes = handshake.getHandshake();
stream.Write(bytes, 0, bytes.Length);
stream.Flush();
bool handshakeComplete = false;
List<string> handshakeLines = new List<string>();
string line;
while(!handshakeComplete) {
line = input.ReadLine().Trim();
if (line.Length>0) {
handshakeLines.Add(line);
} else {
handshakeComplete = true;
}
}
char[] response = new char[16];
input.ReadBlock(response, 0, response.Length);
handshake.verifyServerStatusLine(handshakeLines[0]);
/* Verifying handshake fails... */
//handshake.verifyServerResponse(response);
handshakeLines.RemoveAt(0);
Dictionary<string, string> headers = new Dictionary<string, string>();
foreach (string l in handshakeLines) {
string[] keyValue = l.Split(new char[] {':'},2);
headers.Add(keyValue[0].Trim(), keyValue[1].Trim());
}
handshake.verifyServerHandshakeHeaders(headers);
receiver = new SocketIoClientReceiver(this);
connected = true;
eventHandler.OnOpen();
(new Thread(receiver.run)).Start();
} catch (SocketIoClientException wse) {
throw wse;
} catch (IOException ioe) {
throw new SocketIoClientException("error while connecting: " + ioe.StackTrace, ioe);
}
}
示例4: GetText
/// Get the text to be formatted.
/// Usually the text would be obtained from an edit control.
private static String GetText(string filePath)
{
// create input buffers
int readSize = 131072; // 128 KB
StringBuilder bufferIn = new StringBuilder(readSize);
char[] fileIn = new char[readSize];
// read file data
try
{ FileStream file = new FileStream(filePath, FileMode.Open);
StreamReader streamIn = new StreamReader(file);
// use ReadBlock to preserve the current line endings
int charsIn = streamIn.ReadBlock(fileIn, 0, readSize);
while (charsIn != 0)
{ bufferIn.Append(fileIn, 0, charsIn);
charsIn = streamIn.ReadBlock(fileIn, 0, readSize);
}
streamIn.Close();
}
catch (DirectoryNotFoundException e)
{ Console.WriteLine(e.ToString());
Error("Cannot find directory", filePath);
}
catch (FileNotFoundException e)
{ Console.WriteLine(e.ToString());
Error("Cannot find file", filePath);
}
catch (Exception e)
{ Console.WriteLine(e.ToString());
Error("Error reading file", filePath);
}
return bufferIn.ToString();
}