package com.opensourzesupport.parsers; import com.opensourzesupport.parsers.model.User; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.coury.jfilehelpers.engines.FileHelperEngine; /** * * @author Prasobh.K */ public class TestJHelper { public static void main(String[] args) throws IOException { FileHelperEngine<User> engine = new FileHelperEngine<User>(User.class); List<User> users = new ArrayList<User>(); users = engine.readFile("src/data.txt"); for (User user : users) { System.out.println("User "+user); } } }
User.java
package com.opensourzesupport.parsers.model; import org.coury.jfilehelpers.annotations.FieldFixedLength; /** * * @author Prasobh.K */ public class User { @FieldFixedLength(11) private String name; @FieldFixedLength(2) private Integer age; @FieldFixedLength(16) private String address; @FieldFixedLength(16) private String areaOfProfession; @FieldFixedLength(15) private String designation; @FieldFixedLength(8) private String salary; public String getName() { return name; } public Integer getAge() { return age; } public String getAddress() { return address; } public String getAreaOfProfession() { return areaOfProfession; } public String getDesignation() { return designation; } public String getSalary() { return salary; } public void setSalary(String salary) { this.salary = salary; } public void setAddress(String address) { this.address = address; } public void setAge(Integer age) { this.age = age; } public void setAreaOfProfession(String areaOfProfession) { this.areaOfProfession = areaOfProfession; } public void setDesignation(String designation) { this.designation = designation; } public void setName(String name) { this.name = name; } @Override public String toString() { return "User1{" + "name=" + name + ", age=" + age + ", address=" + address + ", areaOfProfession=" + areaOfProfession + ", designation=" + designation + ", salary=" + salary + '}'; } }
data.txt
Prasobh 26 kollattu IT Tech Lead 25000.02
Reena 18 veettil IT ProjectManager 25000.02
Ronald 25 kollattu IT ProjectLeader 25000.02
Vinu 22 kollattu IT ClarityAdmin 25000.02
Output :
User User{name=Prasobh , age=26, address= kollattu , areaOfProfession=IT , designation=Tech Lead , salary=25000.02}
User User{name=Reena , age=18, address= veettil , areaOfProfession=IT , designation=ProjectManager , salary=25000.02}
User User{name=Ronald , age=25, address= kollattu , areaOfProfession=IT , designation=ProjectLeader , salary=25000.02}
User User{name=Vinu , age=22, address= kollattu , areaOfProfession=IT , designation=ClarityAdmin , salary=25000.02}
Library used:
jfilehelpers-0.2a-20080607.jar
No comments:
Post a Comment