package FileHandling;
public class Candidate {
private int experience;
private String name;
private String primarySkill;
private String qualification;
public int getExperience() {
return experience;
}
public void setExperience(int experience) {
this.experience = experience;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrimarySkill() {
return primarySkill;
}
public void setPrimarySkill(String primarySkill) {
this.primarySkill = primarySkill;
}
public String getQualification() {
return qualification;
}
public void setQualification(String qualification) {
this.qualification = qualification;
}
public String toString() {
return "Candidate [name=" + name + ", primarySkill=" + primarySkill+ ",experience=" + experience + ", qualification=" + qualification+ "]";
}
}
public class Candidate {
private int experience;
private String name;
private String primarySkill;
private String qualification;
public int getExperience() {
return experience;
}
public void setExperience(int experience) {
this.experience = experience;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrimarySkill() {
return primarySkill;
}
public void setPrimarySkill(String primarySkill) {
this.primarySkill = primarySkill;
}
public String getQualification() {
return qualification;
}
public void setQualification(String qualification) {
this.qualification = qualification;
}
public String toString() {
return "Candidate [name=" + name + ", primarySkill=" + primarySkill+ ",experience=" + experience + ", qualification=" + qualification+ "]";
}
}
package FileHandling;
import java.io.*;
public class FileToObjectDemo {
public static Candidate createObjectFromFile(Reader re) throws IOException
{
FileReader red=(FileReader)re;
Candidate cd=new Candidate();
BufferedReader buf=new BufferedReader(red);
StringBuffer strbuf=new StringBuffer();
String line;
while((line=buf.readLine())!=null)
{
strbuf.append(line);
int index,count=3;
System.out.println(" ");
while(count>0)
{
index=strbuf.indexOf(",");
System.out.println(strbuf.substring(0, strbuf.indexOf(",")));
strbuf.delete(0,index+1);
count--;
}
System.out.println(strbuf);
strbuf.delete(0, strbuf.length());
}
red.close();
return cd;
}
public static void main(String[] args) throws IOException {
Reader read=new FileReader("abhishek.txt");
createObjectFromFile(read);
}
}
0 comments:
Post a Comment