EmaadAli
asked on
How to create a CSV file in java
Hi,
I have a requirement to create a CSV file using this open source package au.com.bytecode.opencsv.CS VWriter;
Here is what my requirement is:
1) Retrieve User information from database. I get it in the Java Bean object:- I have done this part here is the sample code
List<BusinessUser> users = usedao.getUsers();
//CSVWriter writer = new CSVWriter(new Writer("path"), "|" );
if (users != null && users.size() > 1) {
Iterator<BusinessUser> it = users.iterator();
while (it.hasNext()){
BusinessUser bu = it.next();
// Test
String loginName = bu.getLoginName();
String firstName = bu.getFistName();
String lastName = bu.getLastName();
}
}
2) public void createHeaderToCSVFile(){
// Header name are" Login Name", "First Name" "Last Name".... there are more colums, but to make it easy for the post I have included only 3 columns
}
3) public void writeRowToCSVFile(){
}
Can someone please help me on this. I need to use | delimeter.
Thanks
I have a requirement to create a CSV file using this open source package au.com.bytecode.opencsv.CS
Here is what my requirement is:
1) Retrieve User information from database. I get it in the Java Bean object:- I have done this part here is the sample code
List<BusinessUser> users = usedao.getUsers();
//CSVWriter writer = new CSVWriter(new Writer("path"), "|" );
if (users != null && users.size() > 1) {
Iterator<BusinessUser> it = users.iterator();
while (it.hasNext()){
BusinessUser bu = it.next();
// Test
String loginName = bu.getLoginName();
String firstName = bu.getFistName();
String lastName = bu.getLastName();
}
}
2) public void createHeaderToCSVFile(){
// Header name are" Login Name", "First Name" "Last Name".... there are more colums, but to make it easy for the post I have included only 3 columns
}
3) public void writeRowToCSVFile(){
}
Can someone please help me on this. I need to use | delimeter.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, both your inputs helped.
ASKER