After verifing this post in stackoverflow I am using indexOf()
method to parse values from file. Below is the format of my file-
10/05/2005 10:02;AM;a@xyz.com;student=student1 std=X marks=87 rollnumber=102
10/05/2005 10:05;AM;b@xyz.com;student=student2 std=IX rollnumber=26
10/05/2005 10:15;PM;c@xyz.com;student=student3 std=VII marks=87 attandance=5 rollnumber=12
10/05/2005 10:32;AM;d@xyz.com;student=student4 std=V marks=87 rollnumber=69
Note:The domain name
i.e. xyz.com
in email is not going to be changed in anywhere.
Below is the code snippet i am using currently-
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(
fis));
String line = "";
while ((line = br.readLine()) != null) {
int index = -1;
if ((index = line.indexOf("xyz.com")) != -1) {
int inStudent = line.indexOf("student=", index);
int spaceExistsinStudent = -1;
int studentIndex = -1;
if ((spaceExistsinStudent = line.indexOf("student=\"", inStudent)) != -1)
studentIndex = line.indexOf(" ", inStudent);
else
studentIndex = line.indexOf("\" ", spaceExistsinStudent);
int inSTD = line.indexOf("std=", studentIndex);
int spaceExistsinSTD = -1;
int stdIndex = -1;
if ((spaceExistsinSTD = line.indexOf("std=\"", inSTD)) != -1)
stdIndex = line.indexOf(" ", inSTD);
else
stdIndex = line.indexOf("\" ", spaceExistsinSTD);
String studentName = line.substring(inStudent + 9, studentIndex);
String stdName = line.substring(inSTD + 4, stdIndex);
There is no need to paste the entire code.
Well, using the above implementation, i am able to work, but is this effective solution as performace is considered? Any better way for achiveing the same....
Thank you in advance.