开发者

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

开发者 https://www.devze.com 2022-12-29 09:30 出处:网络
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:

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

精彩评论

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

关注公众号