|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcommon.TabularReader
public class TabularReader
Reads tabular files, that is, files where each line represents a row, and
each row is broken up into fields (columns) by separator characters. For
example, a comma-separated values (CSV) file is a tabular file where the
separator character is a comma. Other common separator characters are
tabs and colons.
A TabularReader supports reading one line at a time. As with
BufferedReader.readLine, a line is terminated by "\r", "\n", or
"\r\n" (or the end of the file). Each line is returned in the form
of an array of Strings, where each String is a field. Fields may
be empty (if a line contains two consecutive separator characters)
and the number of fields may vary from line to line.
By default, a TabularReader handles empty lines just like any other
line (a blank line yields a zero-length array of fields). But if
you use the three-argument constructor with skipEmptyLines
set to true
, it behaves as if empty lines were not in
the file.
Constructor Summary | |
---|---|
TabularReader(java.io.InputStream stream,
char sep)
Create a new TabularReader that reads from the given input stream and uses the given separator character. |
|
TabularReader(java.io.InputStream stream,
char sep,
boolean skipEmptyLines)
Create a new TabularReader that reads from the given input stream and uses the given separator character. |
Method Summary | |
---|---|
void |
close()
Close the underlying stream. |
static void |
main(java.lang.String[] args)
Test program: given a filename, read it as a tabular file and print it in a comma-separated format. |
java.lang.String[] |
peek()
Returns an array of strings representing the fields of the next line in the input stream, but does not move on to the following line. |
java.lang.String[] |
readLine()
Returns an array of strings representing the fields of the next line in the input stream, and moves on to the line after that. |
boolean |
ready()
Returns true if there is another line to read from the input stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TabularReader(java.io.InputStream stream, char sep) throws java.io.IOException
java.io.IOException
public TabularReader(java.io.InputStream stream, char sep, boolean skipEmptyLines) throws java.io.IOException
skipEmptyLines
is true, this reader will act as if empty lines were not in the file.
java.io.IOException
Method Detail |
---|
public void close() throws java.io.IOException
java.io.IOException
public boolean ready()
public java.lang.String[] readLine() throws java.io.IOException
java.io.IOException
public java.lang.String[] peek() throws java.io.IOException
java.io.IOException
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |