Last active
October 30, 2023 18:47
-
-
Save MatthijsKamstra/e879e62caf146f9bde55afb8e0753705 to your computer and use it in GitHub Desktop.
Write to a file in Haxe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
haxe -main Main --interp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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