I have this CSV File.
City,Job,Salary
Delhi,Doctors,500
Delhi,Lawyers,400
Delhi,Plumbers,100
London,Doctors,800
London,Lawyers,700
London,Plumbers,300
Tokyo,Doctors,900
Tokyo,Lawyers,800
Tokyo,Plumbers,400
Lawyers,Doctors,300
Lawyers,Lawyers,400
Lawyers,Plumbers,500
Hong Kong,Doctors,1800
Hong Kong,Lawyers,1100
Hong Kong,Plumbers,1000
Moscow,Doctors,300
Moscow,Lawyers,200
Moscow,Plumbers,100
Berlin,Doctors,800
Berlin,Plumbers,900
Paris,Doctors,900
Paris,Lawyers,800
Paris,Plumbers,500
Paris,Dog catchers,400
I have the code, which does multiple operations in the CSV File. Now I want to count the characters and also want to append a line to CSV File at the bottom.
import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String args[]) throws IOException
{
String csv="C:\\Users\\Dipayan\\Desktop\\salaries.csv";
BufferedReader br= new BufferedReader(new FileReader(csv));
String line="";
int count=0;
String str[]=new String[200];
int[] a=new int[24];
try {
br.readLine();
while((line = br.readLine())!=null)
{
String[] f=line.split(",");
a[count]=Integer.parseInt(f[2]);
str[count]=f[1];
count++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Arrays.sort(a);
for(int i:a)
{
System.out.println(i);
}
System.out.println("min="+a[0]);
System.out.println("Max="+a[count-1]);
// String sorting
String min1=str[0];
for(int i=0;i<count;i++)
{
if(str[i].compareTo(min1)<0)
min1=str[i];
}
System.out.println(min1);
/*String Sort end*/
/*Finding the Median*/
int median;
if(a.length%2==0)
median = a[a.length/2]+a[(a.length/2)+1];
else
median=a[a.length/2];
System.out.println("Median"+median);
/*Median*/
System.out.println("Line"+count);
}
}