File IO (Input Output)

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/60

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:34 PM on 4/8/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

61 Terms

1
New cards

What do streams do?

Transfer data to and from a program

2
New cards

What is an input stream?

Data flowing into the program (reading from a file)

3
New cards

What is an output stream?

Data flowing out of the program (writing to a file)

4
New cards

What are the two types of streams?

Text streams (Characters). Byte streams

5
New cards

Features of Text streams (2)

  • Handles 16-bit unicode characters

  • Used for .txt/.csv and source code

6
New cards

What classes are used on text streams? (2)

Reader and Writer

7
New cards

What classes are used on byte streams? (2)

InputStream and OutputStream

8
New cards

Features of Byte streams (2)

  • Handles raw 8-bit binary data

  • Used for images/audio and compiled files

9
New cards

What does delimited mean?

Using a character such as space/comma (CSV) or tab to mark the end of a field

10
New cards

What does fixed-width mean?

When every field takes up exactly 4 characters regardless of its value

11
New cards

What are the text packing methods for Text streams (2)

Delimited. Fixed-width

12
New cards

Do byte streams use delimiters?

No

13
New cards

What do byte streams use to separate fields?

Size and order

14
New cards

Both … and … must agree on number of …

Reader. Writer. Bits

15
New cards

What is the “drift” problem?

If input stream reads a smaller value (32) where output stream wrote larger (64)

16
New cards

What does the “drift” problem cause?

Creates error and entire stream becomes garbage

17
New cards

Can java give an error when working with files?

No

18
New cards

Name 2 classes that can handle text files

OutputFile. InputFile

19
New cards

What is the OutputFile Class?

Provides methods to write basic java types to a text file

20
New cards

What is the InputFile Class?

Provides methods to read primitives and Strings back from a text file

21
New cards

What is a path?

Location of a file

22
New cards

What is an absolute path?

Full specific address e.g. C:\Users\Cinema\theater.txt

23
New cards

Negative of absolute files

If the project is moved the path breaks

24
New cards

What is a relative path?

Address relative to the Project Root. e.g. “data/logs.txt” or “theater.txt“

25
New cards

Benefit of relative path

Portability

26
New cards

What is portability

Project is portable without changes

27
New cards

Example of an output file object creation

OutputFIle out = new OutputFile(“bpm.txt“)

28
New cards

What is “out”? (Example of outputfile object creation)

Name of object

29
New cards

What is “new”? (Example of outputfile object creation)

Opens file

30
New cards

What does out.println do? (OutputFile)

Writes value to file

31
New cards

What does out.close do? (OutputFile)

Saves and closes file

32
New cards

What does .eof() return?

Boolean as to whether you are at the end of a file

33
New cards

What should you check before reading from an input file?

If .eof() is false then read

34
New cards

What does it mean when .eof() is false?

There’s still data

35
New cards

What does it mean when .eof() is true?

When end of file is reached

36
New cards

Explain the hierarchal structure of classes

Wrapped inside one another to add functionality

37
New cards

What does FileWriter/FileReader do?

Connects directly to file on disk

38
New cards

What does BufferedWriter/BufferedReader do?

Adds a memory buffer for efficiency

39
New cards

What does PrintWriter do?

Adds high-level methods like println() and printf()

40
New cards

Explain wrapping

Wrap a low-level FileWriter inside a high-level PrintWriter to get disk connectivity + easy formatting

41
New cards

Is Disk access slower or RAM access?

Disk access

42
New cards

Explain the benefit of buffering

Writing 1 byte at a time to hardrive is slow. Fill buffer in RAM then drive to disk

43
New cards

Can you write primitives directly?

Yes using println() PrintWriter class

44
New cards

Benefit of using try with resources (classes in try-catch bracket)

Automatically closes and causes chain-reaction which closes all nested classes

45
New cards

What does .exists() do?

Checks to see if file exists

46
New cards

What does .canRead() do?

Checks to see if file is readable

47
New cards

What does .getAbsolutePath() do?

Gets exact path of file

48
New cards

What does .length() do?

Metadata- finds length of file

49
New cards

What is metadata?

Data about a file e.g. size/name/last modified

50
New cards

What can be used instead of BufferedReader?

Scanner

51
New cards

Benefit of using Scanner (2)

Extract primitives. Allows to check data type before it is read (type-safe reading)

52
New cards

When to use BufferedReader instead of Scanner?

Bulk text

53
New cards

When to use Scanner instead of BufferedReader?

Handles mixed data

54
New cards

Features of text files (3)

  • Readable (Unicode)

  • Variable width (1 takes 1 byte. 1000 takes 4)

  • Sequential

55
New cards

Features of binary files (3)

  • Machine-readable

  • Fixed width (int always 4 bytes)

  • Random access

56
New cards

File types of binary (2)

.dat and .bin

57
New cards

What is sequential access?

Data read in strict order from start to finish

58
New cards

What is random access?

Data accessed via a pointer that jumps to any address

59
New cards

Formula to find byte address

(record index) x (fixed record size)

60
New cards

How is File IO handled in a project

By one class (high cohesion + low coupling)

61
New cards

What is the GIGO Principle?

“Garbage In Garbage Out.” If a corrupt file is loaded the entire code’s logic will fail