BFOIT - Introduction to Computer Programming

File I/O

Introduction

It is not always possible to include all of the data you want your programs to manipulate within the source code of your programs.

In this lesson, you will learn:

  1. How a program can read text from a file,
  2. How to write text to a file.

Revisiting Our Hangman Game

File Input/Output Procedures

Name Input(s) Description
CLOSE fileObject Wrapup input or output associated with the specified file object.
OPENAPPEND fileName Outputs a file object that can be used to WRITE text onto the end of the specified fileName.
OPENREAD fileName Outputs a file object that can be used to read lines of text from the specified fileName.
OPENWRITE fileName Outputs a file object that can be used to WRITE text to the specified fileName. If the file already exists, its contents are overwritten.
(READLIST) fileObject Outputs a line of text read from the fileObject. The line is parsed into word, list, and/or array members depending upon whitespace, brackets, parenthesis, and sqiggly braces.
(READWORD) fileObject Outputs a line of text read from the fileObject. The full line including all whitespace and punctuation is represented as a word.
WRITE fileObject
textData
Write textData to the specified fileObject.
WRITELN fileObject
textData
Write textData followed by a line separator to the specified fileObject.
Table 20.1

Summary


Back to Arrays
Go to the Table of Contents
On to A Java Program

Public Domain Mark
This work (BFOIT: Introduction to Computer Programming, by Guy M. Haas),
identified by Berkeley Foundation for Opportunities in IT (BFOIT),
is free of known copyright restrictions.