Class FlatFileEx2

All Implemented Interfaces:
AutoCloseable, ResultSet, Wrapper

public class FlatFileEx2 extends FlatFile

Reads in a data set in a space separated form.

This example reads a set of stock prices in a space separated form.

The first few lines of the data set are as follows:

 Date        Open    High    Low     Close   Volume
 28-Apr-03   3.3     3.34    3.27    3.33    37224400
 25-Apr-03   3.35    3.38    3.25    3.26    57117400
 24-Apr-03   3.32    3.40    3.30    3.38    47019800
 23-Apr-03   3.34    3.44    3.30    3.37    63243800
 22-Apr-03   3.24    3.38    3.22    3.36    67392500
 

The first line contains the column names, with a comma as the separator. The rest of the lines contain data, one day per line. The first column is Date data and the last column is int data. All of the rest is double data. A data type class is set for each column. The parser is explicitly set for the date column, because it cannot be guessed by FlatFile. The date's locale is set to US, so that the example will work with a different default locale.

A Tokenizer is created and used that counts multiple separators (spaces) as one separator.

This example extends the class FlatFile. The FlatFileEx2 constructor reads the line containing the column names, parses the names, and sets the column names.

The class FlatFileEx2 is used in the method main. The data set is assumed to be in a file called "SUNW.txt" in the same location as the example class file, so that the getResourceAsStream method can be used to open the file as a stream. Some of the columns are printed out for each stock price.

See Also: