File I/O Flashcards

1
Q

What are Character Streams used for?

A

Reading/writing files that contain ASCII/Unicode data
- Text files
- HTML files
- Program source files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What classes do Byte Streams inherit from?

A

InputStream and OutputStream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What classes do Character Streams inherit from?

A

Reader and Writer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are Byte Streams used for?

A

To read/write low level data
- Image pixels
- Audio data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a file in terms of I/O streams?

A

Can be anything from a disk file to a physical device:
- Screen
- Keyboard
- Mouse

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a stream in terms of I/O streams?

A

An abstraction/interface between the programmer and file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does file I/O work in java?

A
  • Opening the data source: Create a stream and associate it with the data source
  • Accessing the data stream: Read and write from the file
  • Closing the data stream: Close the stream to free up memory and clear any buffered data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the two major types of byte streams in Java?

A
  • FileInputStream & FileOutputStream
  • DataInputStream & DataOutputStream
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the two major types of character streams in Java?

A
  • FileReader & FileWriter
  • BufferedReader & PrintWriter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you create a FileInputStream in Java?

A

FileInputStream fileInputStream = new FileInputStream( filename );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you create a DataOutputStream in Java?

A

DataOutputStream dataOutputStream =new DataOutputStream(new FileOutputStream( filename ));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are ObjectOutputStream and ObjectInputStream used for? Give examples.

A
  • Used to read and write objects from file
  • Can only read and write serializable objects (e.g. Java classes)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Checked Exceptions?

A
  • Problems that occur outside of a program’s control (e.g. Corrupt files)

-These must be dealt with

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are Unchecked exceptions?

A
  • Problems caused by the programmer/user (e.g. ArrayIndexOutOfBounds exception)
  • These can be ignored
How well did you know this?
1
Not at all
2
3
4
5
Perfectly