Export my data on CSV file from app android

前端 未结 1 873
自闭症患者
自闭症患者 2021-02-01 10:06

I have a class:

public class A() {
private List e;
private int nE;
private int nC;
private int tC;
private int bL;
private float mA;
private float mP;
p         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 10:56

    You'll need to use a library such as opencsv (found here: http://sourceforge.net/projects/opencsv/)

    To write data to a file you'll need to do something similar to this:

    String csv = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
    CSVWriter writer = new CSVWriter(new FileWriter(csv));
    
    List data = new ArrayList();
    data.add(new String[] {"India", "New Delhi"});
    data.add(new String[] {"United States", "Washington D.C"});
    data.add(new String[] {"Germany", "Berlin"});
    
    writer.writeAll(data);
    
    writer.close();
    

    (modified from here: http://viralpatel.net/blogs/java-read-write-csv-file/)

    to write a file to storage you will need the following permission:

    
    

    0 讨论(0)
提交回复
热议问题