Write a routine that will Parse CSV files it should read the


Write a routine that will Parse CSV files it should read the name of a file from the command line it should parse the file and put the data into a datastructure it should output the number of elements in the file and the last line of the file Submit a screenshot of the output

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
*/

 Write a routine that will Parse CSV files it should read the name of a file from the command line it should parse the file and put the data into a datastructur
 Write a routine that will Parse CSV files it should read the name of a file from the command line it should parse the file and put the data into a datastructur

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site