import java.util.*;
public class ReadFile {
public static class Em implements Comparable<Em> {
private int id;
private String name;
private double Salary;
public int getId() {
return id;
}
// same get methods for sal and name here
public Em(int id, String name, double e) {
this.id = id;
this.name = name;
this.sal = sal;
}
}
public static void main(String a[]) throws IOException {
String record;
List<Em> eL = new ArrayList<Em>();
BufferedReader be = new BufferedReader(new File("Location"));
List<String> arrList = new ArrayList<>();
try {
while ((record = br.readLine()) != null) {
String[] rows = record.spilt(",");
Em e = null;
int a = Integer.parseInt(rows[0]);
String b = rows[1];
double c = Double.parseDouble(rows[2]);
eL.add(new Em(a, b, c);
arlist.add(Arrays.toString(rows));
System.out.println(eL.toString);
}
} catch(IOException e) {
e.printStackTrace();
}
}
}
Please Note: Location of file is correct. Any typo might be there.
The file contains data as follows:
1,Duke,13000
2,Jake,14000
...
OUTPUT:
[test.ReadFile$Em@7852e922]
[test.ReadFile$Em@7852e922,test.ReadFile$Em@4e25154f]
I need help
- Am I doing it correctly
- Any alternate program will help
Future: I have to write emp details who has maximum salary into another file