File I/O and parsing Flashcards
1
Q
- In general what is a FileReader and how does it work?
- What is the code to use it?
A
- FileReader is meant for reading streams of characters. It reads input from a file, character by character.
- 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>
2
Q
- In general what is a BufferedReader and how does it work?
- What is the code to use it?
A
- 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.
- BufferedReader <yourvarname> = new BufferedReader(<afilereader>);</afilereader></yourvarname>
3
Q
What are BufferedReader’s methods and briefly, what do they do?
A
- read( ) - reads a single character
- readLine( ) - reads a line of text
- close( ) - closes the stream and releases any resources
4
Q
What is the specific code to open a text file and read and print the file, line by line?
A
5
Q
How do you parse a string of words into individual words?
A
String[] parsed = new String[5];
parsed = line.split(“ “);
6
Q
A