Skip to content

Instantly share code, notes, and snippets.

@MatthijsKamstra
Last active October 30, 2023 18:47
Show Gist options
  • Save MatthijsKamstra/e879e62caf146f9bde55afb8e0753705 to your computer and use it in GitHub Desktop.
Save MatthijsKamstra/e879e62caf146f9bde55afb8e0753705 to your computer and use it in GitHub Desktop.
Write to a file in Haxe
package;
/**
* Main class for a simple file writing example.
* Author: Matthijs Kamstra aka [mck]
*/
class Main {
/**
* Constructor for the Main class.
* It demonstrates how to write a string to a file.
*/
function new() {
// Print a message to the console
trace('Writing example 🖊️👋');
// Define the string we want to write to the disk, including the current date
var str:String = 'Hello World!\nWritten on: ' + Date.now().toString();
// Write the string to a file named 'hello.txt'
sys.io.File.saveContent('hello.txt', str);
}
/**
* The main entry point for the application.
* If you want certain code to run automatically, put it in
* a static main function and specify the class in the compiler arguments.
*/
static public function main() {
// Create an instance of the Main class
var main = new Main();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment