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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access