I want to write some data in csv format and open it using Excel.Below is the code I am trying to achieve it,
public void writeOutput(String fileName,Map<String){
try {
String jsonData="{"adjustments":[{"adjustmentType":"RENEWAL_OPTION_AMORTIZING_RENEWAL","rate":0.0400},{"adjustmentType":"AMORTIZATION_TERM_LESS_THAN_25_YEARS","rate":-0.0800}],"errorTypes":[],"premiumTaxs":[{"taxType":"STATE_TAX","taxPercent":1.3,"taxAmount":null,"taxJurisdictionName":"Florida"}],"renewalPremiums":[{"rate":0.8100,"rateDurationMonths":168,"sequence":1}],"totalInitialRate":0.8100,"rateName":"Standard National Monthly Non Refundable BPMI Rates","rateCardId":"NABM_NR","ratingInfoBaseRate":0.8500,"optimumPricing":false,"miPricingVO":null,"addressMatchCode":null}";
String dataID = "MyNewDataID";
OutputStreamWriter writer = new OutputStreamWriter(
new FileOutputStream(System.getProperty("user.dir")
+ "\\test\\" + fileName + ".csv", true),"UTF-8");
BufferedWriter fbw = new BufferedWriter(writer);
fbw.write(dataID + "," + jsonData);
fbw.newLine();
fbw.close();
}catch (Exception e) {
System.out.println(e.getCause());
System.out.println(e.getStackTrace());
}
}
When the above code is executed and when I open the csv file using Excel, all the data(comma separated) are displayed in different cells - I am expecting the String dataID in cell A1 and jsonData in B1. Please help me - how do I achieve this.
Note: I have tried with different delimiters and It didn't work.
Thanks, Mike