Writing into a Text File in Gosu
To write into a text file in gosu we can use the FileWriter as follows:
using(var writer = new BufferedWriter(new FileWriter("<FILENAME>"))) {
writer.write("<TEXT>") // Writes a text to into a file.
writer.flush() // Must be at the last.
}
| Token | Description |
| FILENAME | The target filename to write into. |
| TEXT | The text to write into the filename. You can write as many text as you like. Just don't forget the flush method at the end. |
Reading from a Text File in Gosu
To read from a text file in gosu we can use the FileReader with Scanner as follows:
using (var scanner = new Scanner(new BufferedReader(new FileReader("<FILENAME>")))) {
while(scanner.hasNext()) {
print(scanner.nextLine()) //---Reads a line from the file.
}
}
| Token | Description |
| FILENAME | The target filename to read from. |
Recent Comments