Create .csv File In Android Application
How can create .csv file in android application, in which we will store some data like some employe details?
Solution 1:
download library from here
and jar file add to your application.
Inside your application do
CSVWriterwriter=null;
try
{
writer = newCSVWriter(newFileWriter("/sdcard/myfile.csv"), ',');
String[] entries = "first#second#third".split("#"); // array of your values
writer.writeNext(entries);
writer.close();
}
catch (IOException e)
{
//error
}
Solution 2:
You can write your own implementation for example using String.format or MessageFormat, you can use a template engine like StringTemplate or you can use tools like Bindy.
Example using bindy:
@CsvRecord(isOrdered = true)public Class Order {
@DataField(pos = 1, position = 11)privateint orderNr;
@DataField(pos = 2, position = 10)private String clientNr;
...
}
I'm not sure you can use bindy without camel-core, if not then it's probably a dependency you don't want in an Android app ;)
There are loads of other options as well.
Post a Comment for "Create .csv File In Android Application"