Files

What can we do with files?

Printing to file

Appending to file is writing to an already existing file

Will need a FileWriter and a PrintWriter

Use the PrintWriter as a "shell for the FileWriter"

In other words, declare the file writer AND the file which it will append to, inside of the printWriters declaration brackets.

When declaring both, remember to write ", true"

Saying "true" effectively tells the program that the named file is Appendable.

REMEMBER TO CLOSE YOUR PRINTWRITER, or else your output to the file will NOT SAVE.

You do not need to close your FileWriter, this will happen when you close the PrintWriter which it is contained inside of.

Writing a name for a file, which does not exist in the immediately accessible file of the java project, will CREATE a file.

Need to import and declare PrintWriter

Give a name to the file which will be written to

REMEMBER TO CLOSE YOUR PRINTWRITER, or else your output to the file will NOT SAVE.

Reading from file

Scanners can be used to read from files

When declaring a scanner, unless the file is in the same folder as the program, copy and paste the shortcut in memory from your files.

.txt specifies that something is a text file, this is EVEN done when writing a file name in quotes.

Reading from file, just like printing to file, will need to be directed towards a specific place in memory. SPECIFICITY really really matters, as not specifying WHERE something is in memory will result in your desired file not being read.

What is a file?

A file is a collection of data stored in memory

Organization is really important

Files, folders, drives, devices, these are all levels of organization

Understanding where a file can be accessed is essential for understanding computers as a whole, as every file is organized SOMEWHERE

Text files act like arrays

Each line of the array is like a new element, and each even has their own index, like an array!

Keep in mind that the array should be visualized vertically, just for correctness. Technically in memory there is no actual directionality to the data's storage, but if asked, illustrate it as a vertical array.