开发者

How can I append the content of a.bin to b.bin in Powershell?

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜