Presentation is loading. Please wait.

Presentation is loading. Please wait.

READING AND WRITING FILES. READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential.

Similar presentations


Presentation on theme: "READING AND WRITING FILES. READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential."— Presentation transcript:

1 READING AND WRITING FILES

2 READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential Method  Files are read and written from beginning to end one item at a time.  Items can be words, characters, separated by commas or a complete line of data.

3 OPEN  The open statement  Opens a file  Mode  A way that a file can be opened for sequential access.

4 LINE INPUT STATEMENT  Reads from the file, ignoring commas in the input stream and completing the data item only at the next carriage return or at the end of file

5 OUTPUT MODE  This is a mode for writing to a file  There must be an open statement when using the OUTPUT mode. Example Open “example.txt” for output as #handle  Code that writes to the file called example.txt must include a reference of #handle.  Rule of thumb:  You cannot have more than one file open at a time that uses the same file handle or your program will terminate with an error.

6 INPUT MODE  Reads sequentially from a file. Example  Open “example.txt” for input as #example

7 CLOSE STATEMENT  Used for closing open files when reading and writing programs. Examples for writing and reading files  Open “example.txt” for output #example  Close #example  Open “example.txt” as input #example  Close #example

8 PRINT STATEMENT  Another purpose for the print statement is to:  Write into a file opened for sequential output EXAMPLE  Open “example.txt” for output as #example  Print “example, “Congratulations,”  Print “example, “you got correct!!”  Close “example

9 .TXT FILES  These are files created using a notepad file.

10 ASSIGNMENT: TUTORIAL WEEK 3  Sequential Files Worksheet


Download ppt "READING AND WRITING FILES. READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential."

Similar presentations


Ads by Google