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

Note

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.