Inverted file
Last updated:
8/23/2020
⁃
Difficulty:
Intermediate
Create a program in C# that inverts all the bytes of a binary file. You can use the FileStream
object to read and write binary files.
You must create a new file with the same name but with the extension .inv.
Input
Output
Solution
using System.IO;
class InvertedFile
{
public static void Main(string[] args)
{
string inputFileName = "app.exe";
string outputFileName = "app.inv";
using (FileStream file = File.OpenRead(inputFileName))
{
long size = file.Length;
byte[] data = new byte[size];
file.Read(data, 0, (int)size);
using (FileStream outFile = File.Create(outputFileName))
{
for (long i = size - 1; i >= 0; i--)
{
outFile.WriteByte(data[i]);
}
}
}
}
}