File formats

The Countries.dat data file in the preceding example is a flat file—an ordinary text file with no special structure or formatting. It is the simplest kind of data file.

Another simple, common format for data files is the comma separated values (CSV) file. It is also a text file, but uses commas instead of blanks to separate the data values. Here is the same data as before, in CSV format:

File formats

Figure 2-4 A CSV data file


In this example, we have added a header line that identifies the columns by name: Country and Population.

For Java to process this correctly, we must tell the Scanner object to use the comma as a delimiter. This is done at ...

Get Java Data Analysis now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.