import java.io.FileOutputStream;
import java.io.IOException;
public class App {
public void writeMessageToFile(String filename, String message) {
try (FileOutputStream fos = new FileOutputStream(filename)) {
byte[] messageBytes = message.getBytes();
fos.write(messageBytes);
System.out.println("Successfully wrote message to " + filename);
} catch (IOException e) {
System.err.println("Error writing file: " + e.getMessage());
}
}
public static void main(String[] args) {
App app = new App();
String message = "This message will be converted into raw bytes in ASCII format. "+
"These bytes are written to a file using FileOutputStream";
app.writeMessageToFile("message.bin", message);
}
}