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


C# StreamReader.ReadBlock方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:jiteshjha,项目名称:TextEditor,代码行数:12,代码来源:texteditor.cs

示例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);
    }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:8,代码来源:clisp.cs

示例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);
		}
	}
开发者ID:kpro1999,项目名称:socket.io-unity-client,代码行数:54,代码来源:SocketIoClientConnection.cs

示例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();
    }
开发者ID:azat-archive,项目名称:astyle,代码行数:36,代码来源:Example2.cs


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