I have a method called createCSV where I convert a List into a csv file. I want to use a pathname for the new file with the name of the List, which I give as a param. How can i do this? Here is my code:
public static File createCSV(List<String[]> custList) {
String methodName = "createCSV";
String csv = "/home/oracle/outputcsv/" + custList + ".csv"; // pathname
// with
// listname.csv
File file = new File(csv);
try {
custList = new ArrayList<String[]>();
FileWriter filewr = new FileWriter(file);
CSVWriter writer = new CSVWriter(filewr);
custList.add(0, new String[] { "customerId" });
for (String[] list : custList) {
custList.add(0, new String[] { "customerId" });
}
writer.writeAll(custList);
logger.debug("[{}] custlist = {}", methodName, custList);
logger.debug("[{}]CSV written successfully", methodName);
writer.close();
logger.debug("[{}]The file is supposed to be :) : {} ", methodName,
file);
// return file;
} catch (IOException e) {
e.printStackTrace();
logger.debug("[{}] IOException {}", methodName, e);
}
return file;
}
I also have a problem in displaying all my list elements. I tried to use a for statement but it didn't help.
Thanks a lot!