using System.IO; string filePath = @"C:\testfile.txt"; // create a new file or overwrite if already exists using (FileStream fs = new FileStream(filePath, FileMode.Create)) { string data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; byte[] info = new UTF8Encoding(true).GetBytes(data); fs.Write(info, 0, info.Length); }
using System.IO; string filePath = @"C:\testfile.bin"; // create a new file or overwrite if already exists using (FileStream fs = new FileStream(filePath, FileMode.Create)) { byte[] data = { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64 }; fs.Write(data, 0, data.Length); }In the above example, we create a binary file with the path `C:\testfile.txt` and write the bytes `{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64 }` to it. These examples belong to the C# System.IO namespace.