本文整理汇总了C#中System.IO.FileStream.ReadToEnd方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.ReadToEnd方法的具体用法?C# FileStream.ReadToEnd怎么用?C# FileStream.ReadToEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了FileStream.ReadToEnd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplicationStream
/// <summary>
/// Create the stream object
/// </summary>
/// <param name="asm">The assembly to read or write</param>
public ApplicationStream(Assembly asm)
{
this.assembly = asm;
this.tmpContentFile = Path.GetTempFileName();
new FileInfo(tmpContentFile).DeleteOnExit();
this.tmpAssemblyFile = Path.GetTempFileName();
new FileInfo(tmpAssemblyFile).DeleteOnExit();
File.Copy(assembly.Location, tmpAssemblyFile, true);
//Out file (Assembly)
using (FileStream tmpOut = new FileStream(tmpAssemblyFile, FileMode.Open))
{
//In file (Temporary)
using (FileStream tmpIn = new FileStream(tmpContentFile, FileMode.Create))
{
int read = 0;
uint counter = 0;
//Search pasttern
while (tmpOut.Length > tmpOut.Position)
{
//Read byte
read = tmpOut.ReadByte();
//Byte is the signature byte (dependence of counter state)
if (read == signature[counter])
{
counter++; //Add counter (goon in signature byte array)
if (counter >= signature.Length) //Is counter full (end of signature byte array)
{
//Copy to tmp stream
byte[] buffer = tmpOut.ReadToEnd();
tmpIn.Write(buffer, 0, buffer.Length);
//Clear data from exe (cut it)
long length = buffer.Length + signature.Length;
tmpOut.SetLength(tmpOut.Length - length);
//Break while
break;
}
}
else //Byte is not the signature byte
counter = 0; //Reset counter (search signature from start)
}
tmpIn.Close();
}
tmpOut.Close();
}
//Set stream to temporary file
this.stream = new FileStream(tmpContentFile, FileMode.Open);
}
示例2: OnSetKey
/// <summary>
/// An event handler called when setting the key for a PlanetLab slice.
/// </summary>
/// <param name="sender">The sender object.</param>
/// <param name="e">The event arguments.</param>
private void OnSetKey(object sender, EventArgs e)
{
// Open the dialog.
if (this.openFileDialog.ShowDialog(this) == DialogResult.OK)
{
try
{
// Open the file.
using (FileStream fileStream = new FileStream(this.openFileDialog.FileName, FileMode.Open))
{
// Set the key data.
this.config.Key = fileStream.ReadToEnd();
}
}
catch (Exception exception)
{
// Show an error dialog if an exception is thrown.
MessageBox.Show("Could not open the RSA key file. {0}".FormatWith(exception.Message), "Cannot Open File", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
示例3: OnLoadKey
/// <summary>
/// An event handler called when loading the data from a file.
/// </summary>
/// <param name="sender">The sender object.</param>
/// <param name="e">The event arguments.</param>
private void OnLoadKey(object sender, EventArgs e)
{
// Set the dialog filer.
this.openFileDialog.Filter = "All files (*.*)|*.*";
// Open the dialog.
if (this.openFileDialog.ShowDialog(this) == DialogResult.OK)
{
try
{
// Open the file.
using (FileStream fileStream = new FileStream(this.openFileDialog.FileName, FileMode.Open))
{
// Get the key data.
this.sshKey = fileStream.ReadToEnd();
// Set the key data as a string to the text box.
this.textBoxKey.Text = this.sshKey != null ? Encoding.UTF8.GetString(this.sshKey).Replace("\n", Environment.NewLine) : string.Empty;
}
}
catch (Exception exception)
{
// Show an error dialog if an exception is thrown.
MessageBox.Show("Could not open the RSA key file. {0}".FormatWith(exception.Message), "Cannot Open File", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}