I need to code a program to compare the datas in .csv file (.csv file is an excel file which will be seperated by , instead of cells by saving in.csv format). I've coded it fully and the required outout is also obtained. But i need a modified version of this code (logic can be changed or the entire functions can be changed but the outout is to be same)
package scannerexample;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class ScannerExample
@SuppressWarnings("empty-statement")
public static void main(String[] args) throws FileNotFoundException, IOException
{
//Input file which needs to be parsed
String fileToParse1 = "E://Java Project/SampleCSVFile1.csv";
String fileToParse2 = "E://Java Project/SampleCSVFile2.csv";
ScannerExample obj = new ScannerExample ();
obj.highestAttenMark(fileToParse1);
obj.highestAttenMark(fileToParse2);
}
public void highestAttenMark(String filename) {
BufferedReader fileReader = null;
int i=0;
//Delimiter used in CSV file
final String DELIMITER = ",";
try
{
String line = "";
String name=null;
int atmark=0;
//Create the file reader
fileReader = new BufferedReader(new FileReader(filename));
//Read the file line by line
while ((line = fileReader.readLine()) != null)
{
//Get all tokens available in line
String[] tokens = line.split(DELIMITER);
if(i!=0) {
if(i==0) {
name=tokens[1];
atmark=Integer.parseInt(tokens[3]);
}
if(atmark<=Integer.parseInt(tokens[3]))
{
name=tokens[1];
atmark=Integer.parseInt(tokens[3]);
}
}
i++;
}
System.out.println(name);
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
It is done by array concept, is there any other concepts to do it other than array. If so kindly provide me the info.
The data in .csv file is as follows
s.no,name,department,marks
1,naveen,ece,98
2,rahul,ece,95
3,kavi,ece,96
Actually i coded it for comparing data in each file (not comparing two files)