Write a routine that will Parse CSV files it should read the
Solution
package twodutiltester;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Test {
public static void main(String[] args) {
BufferedReader bufferReader = null;
String Line= \"\";
int count=0,n=0;
//data structures to store student data
String name[]=new String[10];
int id[]=new int[10];
String dept[]=new String[10];
try {
//reads the name of the file from command line argument
bufferReader = new BufferedReader(new FileReader(args[1]));
//reading data
while ((Line = bufferReader .readLine()) != null) {
//parsing the file using comma as delimiter
String[] items = Line.split(\",\");
//storing data into appropriate data structure
id[n]=Integer.parseInt(items[0]);
name[n]=items[1];
dept[n]=items[2];
n++;
//counting number of elements
count+=items.length;
System.out.println();
}
//display last line of the file
System.out.println(\"Last Line: \"+Line);
//display number of elements
System.out.println(\"Number of elements in file: \"+count);
} catch (FileNotFoundException e) {
} catch (IOException e) {
} finally {
if (bufferReader != null) {
try {
bufferReader .close();
} catch (IOException e) {
}
}
}
}
}
/*
/input file
student.csv
12,Jhon,CSE
23,Mary,ECE
10,Marlin,MBA
*/

