Lesson 24Using Simple File Input and Output
Up to this point, we have been dealing with data as variables (primitives and objects) in memory and occasionally reading values from the console (and then promptly storing these values in a variable). This has worked well, but all of our data disappears when the program completes. To write truly useful programs, we must be able to store data when program execution ends and read that data the next time we run our programs.
In this lesson, we will begin to explore data persistence and ways that we can translate data from variables (in memory) to files (on disk) for long-term storage and then reverse the process when we need to access the data later. We will concentrate on storing data in flat text files for now, but the principles of this lesson continue to be relevant when we start storing data in relational databases.
We will also take a look at one way we can do simple file input and output. For now, however, we'll cover the basics—just enough to get data into and out of files.
DATA STORAGE AND REPRESENTATION
We have two options available to us for data ...
Get Job Ready Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.