/*
* List<string[]> Incoming
* Public method
*/
public static Boolean exportcsv (file file, List dataList) {
Boolean issuccess = false;
if (file = = NULL | |!file.getname (). toUpperCase (). EndsWith (format)) {
Issuccess = false;
} else {
FileOutputStream out = null;
OutputStreamWriter OSW = null;
BufferedWriter bw = NULL;
int i = 1;
try {
BW = new BufferedWriter (new FileWriter (file));
for (int j = 0; J < Datalist.size (); j + +) {
The first line is the title
string[] data = (string[]) Datalist.get (j);
String datastr = "";
for (int k = 0; k < data.length; k++) {
if (k = = data.length-1) {
Datastr = Datastr + data[k];
} else {
Datastr = Datastr + data[k] + ",";
}
}
Bw.write (DATASTR);
Bw.newline ();
}
Bw.flush ();
Issuccess = true;
} catch (IOException e) {
E.printstacktrace ();
Issuccess = false;
} finally {
if (out! = null) {
try {
Out.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
}
}
return issuccess;
}
Call
File csvfile = null;
try {
Generate Temporary files
CSVFile = File.createtempfile ("Template name", "template format");
} catch (IOException e) {
E.printstacktrace ();
}
list<string[]> dataList = new arraylist<string[]> ();
string[] data = new string[]{"name", "Age", "number"}; File Column Name
Datalist.add (data);
Csvutil.exportcsv (CSVFile, dataList);
File download public method and call