Last active
October 30, 2023 18:45
-
-
Save MatthijsKamstra/15efab21735b970c93e251532596f1d6 to your computer and use it in GitHub Desktop.
Reading and writing to a file with 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
package; | |
/** | |
* Main class for reading and writing a simple text file. | |
* Author: Matthijs Kamstra aka [mck] | |
*/ | |
class Main { | |
/** | |
* Constructor for the Main class. | |
* It demonstrates reading and writing operations on a text file. | |
*/ | |
function new() { | |
// Print a message to the console | |
trace("Reading and writing example ๐ค ๐๏ธ"); | |
// Define a string that we want to write to the disk, including the current date | |
var str:String = 'Writing and reading a simple text file!\nWritten on: ' + Date.now().toString(); | |
// Write the string to a file named 'hello.txt' | |
sys.io.File.saveContent('hello.txt', str); | |
// Now, let's read ๐ the file | |
var content = sys.io.File.getContent('hello.txt'); | |
// Print the content of the file to the console | |
trace(content); | |
} | |
/** | |
* The main entry point for the application. | |
* If you want certain code to run automatically, you need to 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