• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/18

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

18 Cards in this Set

  • Front
  • Back

What is the benefit of binary I/O over text I/O?


More efficient. Stores 199 as C7 instead of '1'9'9'. Also does not involve encoding or decoding and is independent of the coding scheme of the host machine
What class is used to read text data? What class is used to write print data?


Scanner


Printwriter


Input classes ____ input streams and output classes ____ output streams

read


write

True or false: all files are stored as binary files


true

What is the abstract root class for reading binary data? Writing binary data?


InputStream




OutputStream

What do you use for reading/writing bytes to/from files?


FileInputStream


FileOutputStream




if the file already exists, be sure to pass true and append to the constructor

Exception handling with InputStream/OutputStream


declare throws IOException in the method or use a try-catch

Why should you use try-with-resources?


file will automatically close when operation are done


try{


open file writer/read}


{


//insert code to be read/written


}



What do filter streams do?


filter bytes for some purpose (e.g., read double, ints, or strings instead of bytes)
What do DataInputStream and DataOutputStream do?

How do you know when you've reach the end of the file?


convert from bytes to primitive/string and vice versa




catch the EOFException

What are BufferedInputStream and BufferedOutputStream used for?

Increase efficiency


BufferedInputStream: whole block of data is read into the buffer in the memory once. Individual data are then delivered from the buffer


BufferedOutputStream: Data are first written to the buffer. When the buffer is full, all data are written to the disk once

Do BufferedInputStream and BufferedOutputStream contain new methods?

no. All methods are inherited from InputStream and OutputStream. Think of BufferedInput/OutputStream as operating in the background

True or false: You should always use buffered I/O to speed up input and output

true

What are ObjectInputStream and ObjectOutputStream used for?

read/write objects, primitives, strings

What's the catch with ObjectInputStream?

objects must be read back from the corresponding ObjectInputStream with the same types and in the same order as they were written. Java's safe casting should be used to get the desired type

Can every object be written to the output stream?

No, it must be Serializable (implement the Serializable interface) --> doesn't have any methods. Just needs to implement it.

If an object is an instance of Serializable but contains nonserializable instance data fields, can it be serialized?


No, but you can mark those fields with keyword transient and the JVM will ignore them when writing the object to the object stream


(e.g., static variable, instance variable)

All of the types so far are sequential streams. What's the alternative?

Random access streams