hai,i m able to write data into notepad but not printing into excel please help me to get out of this error
Employee class:
public class Employee {
private String LeftKey3;
private String LeftKey2;
private String RelationTypeUniqueName;
private String RightKey2;
private String LeftKey1;
private String RightKey1;
private String RightKey3;
private String RightId;
private String LeftId;
public String getLeftKey3() {
return LeftKey3;
}
public void setLeftKey3(String LeftKey3) {
this.LeftKey3 = LeftKey3;
}
public String getLeftKey2() {
return LeftKey2;
}
public void setLeftKey2(String LeftKey2) {
this.LeftKey2 = LeftKey2;
}
public String getRelationTypeUniqueName() {
return RelationTypeUniqueName;
}
public void setRelationTypeUniqueName(String RelationTypeUniqueName) {
this.RelationTypeUniqueName =RelationTypeUniqueName;
}
public String getRightKey2() {
return RightKey2;
}
public void setRightKey2(String RightKey2) {
this.RightKey2 =RightKey2;
}
public String getLeftKey1() {
return LeftKey1;
}
public void setLeftKey1(String LeftKey1) {
this.LeftKey1 =LeftKey1;
}
public String getRightKey1() {
return RightKey1;
}
public void setRightKey1(String RightKey1) {
this.RightKey1 = RightKey1;
}
public String getRightKey3() {
return RightKey3;
}
public void setRightKey3(String RightKey3) {
this.RightKey3 = RightKey3;
}
public String getRightId() {
return RightId;
}
public void setRightId(String RightId) {
this.RightId = RightId;
}
public String getLeftId() {
return LeftId;
}
public void setLeftId(String LeftId) {
this.LeftId= LeftId;
}
public static Comparator<Employee> employeeNameComparator = new Comparator<Employee>() {
public int compare(Employee employee1, Employee employee2) {
String rightKey1 = employee1.getRightKey1();
String rightKey2 = employee2.getRightKey1();
if(rightKey1.contains("|") && rightKey2.contains("|"))
{
int firstemp= Integer.parseInt(rightKey1.substring(0,rightKey1.indexOf('|')));
int secondemp= Integer.parseInt(rightKey2.substring(0,rightKey2.indexOf('|')));
if(firstemp<secondemp)
{
return -1;
}
else if (firstemp>secondemp)
{
return 1;
} else
{
return 0;
}
}
else
{
return rightKey1.compareTo( rightKey2);
}
}
};
public String toString() {
return "\n" + this.LeftKey3 + ", " + this.LeftKey2+ ", " + this.RelationTypeUniqueName + ", " +
this.RightKey2 + ","+ this.LeftKey1 +","+ this.RightKey1 +","+ this.RightKey3 +","+ this.RightId +","+ this.LeftId +"";
}
}
What I have tried:
<pre> private static final String NEW_LINE_SEPARATOR = "\n";
private static final String [] VENDORSUBSIDARY_REPLACE= {"LeftKey3","LeftKey2","RelationType.UniqueName","RightKey2","LeftKey1","RightKey1","RightKey3","RightId","LeftId"};
private static final String [] VENDORCURRENCY_HEADERS={"LeftKey3","LeftKey2","RelationType.UniqueName","RightKey2","LeftKey1","RightKey1","RightKey3","RightId","LeftId"};
public static void main(String args[])throws IOException
{
BufferedReader br = null;
CSVPrinter csvFilePrinter = null;
FileWriter fileWriter = null;
String replacecurrencycodeFile = "C:/Users/Desktop/newsample.csv";
try
{
CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator(NEW_LINE_SEPARATOR);
fileWriter = new FileWriter( replacecurrencycodeFile);
csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat);
csvFilePrinter.printRecord(VENDORSUBSIDARY_REPLACE);
br = new BufferedReader(new FileReader("C:/Users/Desktop/Internalid1.csv"));
List<employee> empList = new ArrayList<employee>();
String line = "";
br.readLine();
while ((line = br.readLine()) != null)
{
String[] employeeDetails = line.split(",");
if(employeeDetails.length != 0 )
{
Employee emp = new Employee(employeeDetails[0], employeeDetails[1],employeeDetails[2],employeeDetails[3],employeeDetails[4],employeeDetails[5],employeeDetails[6],employeeDetails[7],employeeDetails[8]);
empList.add(emp);
}
}
Collections.sort(empList,Employee.employeeNameComparator );
for(Employee e : empList)
{
System.out.println(e);
csvFilePrinter.printRecord(e);
}
System.out.println("done");
br.close();
}
catch (Exception e) {
e.printStackTrace();
} finally {
try {
fileWriter.flush();
fileWriter.close();
csvFilePrinter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}