Enter the following program (You may use cut/paste):
public class ReadCSV
{
public static void main(String[] args) {
ReadCSV ec = new ReadCSV();
System.out.println(ec.csvCollection("us.csv"));
}
public ReadCSV() {
}
public ArrayList csvCollection(String filename) {
ArrayList rslt = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(filename));) {
while (br.ready()) {
String l = br.readLine();
String[] brokenLine = l.split(",", 25);
rslt.add(brokenLine);
}
System.out.println("Lines all read ");
} catch (FileNotFoundException fnf) {
System.err.println("Could not open the file" + fnf);
} catch (IOException ioe) {
System.err.println("Reading problem" + ioe);
}
return rslt;
}
public void echoCSV(String filename)
{
try (BufferedReader br = new BufferedReader(new FileReader(filename));) {
int lineCount = 0;
while (br.ready()) {
String l = br.readLine();
lineCount++;
String[] brokenLine = l.split(",", 25);
System.out.println(lineCount + " ");
for (int i = 0; i < brokenLine.length; i++) {
System.out.print(" "+ i + ":" + brokenLine[i]);
}
}
System.out.println("Lines all read ");
} catch (FileNotFoundException fnf) {
System.err.println("Could not open the file" + fnf);
} catch (IOException ioe) {
System.err.println("Reading problem" + ioe);
}
}
}