using System;
using System.IO;
using System.Security.AccessControl;
class Program
{
static void Main()
{
// Create a byte array of data
byte[] data = { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
// Specify the file path and name
string filePath = @"C:\path\to\file.txt";
// Specify file permissions
FileSecurity fileSecurity = new FileSecurity();
fileSecurity.AddAccessRule(new FileSystemAccessRule("USERNAME", FileSystemRights.FullControl, AccessControlType.Allow));
// Create the file and write bytes to it
using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
// Set the access control on the file
File.SetAccessControl(filePath, fileSecurity);
// Write bytes to the file
fileStream.Write(data, 0, data.Length);
}
Console.WriteLine("File created and bytes written with permissions.");
}
}