File I/O and parsing Flashcards

1
Q
  1. In general what is a FileReader and how does it work?
  2. What is the code to use it?
A
  1. FileReader is meant for reading streams of characters. It reads input from a file, character by character.
  2. FileReader <yourvarname> = new FileReader("<yourfilename>");
    </yourfilename></yourvarname><ul>
    <li>note that this needs to be wrape in a try/catch as it throws a FileNotFoundException</li>
    </ul></yourfilename></yourvarname>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. In general what is a BufferedReader and how does it work?
  2. What is the code to use it?
A
  1. BufferedReader reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream.
  2. BufferedReader <yourvarname> = new BufferedReader(<afilereader>);</afilereader></yourvarname>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are BufferedReader’s methods and briefly, what do they do?

A
  1. read( ) - reads a single character
  2. readLine( ) - reads a line of text
  3. close( ) - closes the stream and releases any resources
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the specific code to open a text file and read and print the file, line by line?

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

How do you parse a string of words into individual words?

A

String[] parsed = new String[5];

parsed = line.split(“ “);

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