Practical Coding in Java

Learn to write and validate your own code

Darren Kessner, PhD

(revised January 9, 2026)

Previous: Coding Exercises: Recursion

14. File IO

Java provides classes for file IO (input/output), which you can use to read and write files. This is useful when you want your program to load or save data.

The following examples show how to use the File and Scanner class to read data from a file. For programs using the Processing libraries, the Processing loadStrings() and saveStrings() functions are generally easier to use. The LoadStrings example shows an implementation of a loadStrings() function.

The HighScores example (Appendix B: Processing Libraries) demonstrates how you can load and save a high score list for a video game.


Next: