In java you can do this:
File file = new File(filepath);
PrintStream pstream = new PrintStream(new FileOutputStream(file));
System.setOut(pstream);
byte[] bytes = GetBytes();
System.out.write(bytes);
I want to do something similar in C#. I tried this but it didn't work:
StreamWriter writer = new StreamWriter(filepath);
Console.SetOut(writer);
byte[] bytes = GetBytes();
Console.Out.Write(bytes);
It looks like the main problem here is that the Write method does not accept an array of bytes as an argument.
I know that I could get away with File.WriteAllBytes(filepath, bytes), but I would like to keep the C# code as close as possible to the original, java code.