public class CSVReader
extends Object
| Modifier and Type | Field and Description |
|---|---|
private static String |
DELIMINATOR
Simply set to a comma "," for now.
|
private Scanner |
fileScanner
Uses a instance variable as the scanner remains open until the
file is completely read.
|
| Constructor and Description |
|---|
CSVReader(String file,
boolean skipHead)
A constructor that requires the name of the file to open.
|
| Modifier and Type | Method and Description |
|---|---|
String[] |
getNext()
Reads a line (nextLine()) and splits
it into a String array by the
DELIMINATOR, if the line is
empty it will return null |
boolean |
hasNext()
Checks to see if the fileScanner has more lines and returns the answer.
|
private static final String DELIMINATOR
private Scanner fileScanner
public CSVReader(String file,
boolean skipHead)
try {
fileScanner = // your code here
// your code here
}catch (FileNotFoundException io) {
System.err.printf("File %s not found%n", file);
System.exit(1);
}
If skipHead is true, call the .nextLine() method immediately, but do nothing
with the results.file - filenameskipHead - skip the head of the file, true or falsepublic String[] getNext()
DELIMINATOR, if the line is
empty it will return nullString.split(String)public boolean hasNext()