How can I append the content of the fi开发者_StackOverflow中文版le a.bin to the file b.bin in Powershell?
Perhaps somebody has a simpler approach but this works:
[byte[]]$bytes = Get-Content a.bin -Encoding byte
Add-Content b.bin $bytes -Encoding byte
If that does not work, there is always this approach:
function AppendFile([string]$Source, [string]$Target)
{
$TargetStream = [System.IO.File]::OpenWrite($Target);
$SourceStream = [System.IO.File]::OpenRead($Source);
$Buffer = New-Object Byte[] 8192;
$TargetStream.Seek(0, [System.IO.SeekOrigin]::End);
while (($BytesRead = $SourceStream.Read($Buffer, 0, $Buffer.Length)) -gt 0)
{
$TargetStream.Write($Buffer, 0, $BytesRead);
}
$TargetStream.Close();
$SourceStream.Close();
}
精彩评论