File IO Flashcards
What is TextInputFile?
storage command provided by arc library to read files
What is TextOutputFile?
storage command provided by arc library to write files
It is good practice to…
close your txt files after using them
Function of:
TextInputFile variablename = TextInputFile(“filename.txt”);
Storage Command
* tells computer to open up the specific file from the hard drive/storage
* gives the file name a variable which can be used throughout program
How do you check to see if your code can open the file?
if no error message appears in the background window
Does variable name for TextInputFile or TextOutputFile have to match the text file?
No
Function of Storage Input Command
tells the computer to read a line from the already opened file
tells the computer to read a line from the already opened file
Function of Storage Input Command
Write the line of code to open text file for reading
TextInputFile variablename = new TextInputFile(“textfilename.txt”);
Write the line of code to open a text file for writing
TextOutputFile variablename = new TextOutputFile(“textfilename.txt”);
Write an example of a Storage Input Command for any variable type
strLine = txtvariablename.readLine();
intLine = txtvariablename.readInt();
dblLine = variablename.readDouble();
Write a line of code to close the opened text file
textvariablename.close();
Function of .eof()
Method which means “End of File”
* looks for a blank line b/w lines or at the end of text and identifies it as the end of code
Write the general structure to read every line of code in a file (as a string)
while(textvariablename.eof() == false) {
strLine = textvariablename.readLine();
}
What is it good practice to do when finished with a file?
to close it