简体   繁体   English

从app android导出我的CSV文件数据

[英]Export my data on CSV file from app android

I have a class: 我有一节课:

public class A() {
private List<B> e;
private int nE;
private int nC;
private int tC;
private int bL;
private float mA;
private float mP;
private int eP;`      }

And a second class: 第二节课:

public class B() {
private String m;
private int v;
private int l;
private int c;
private String d;
private String n;
private Calendar data;
private int t;   }

How can i do to save this information into a CSV file from my app? 如何将此信息保存到我的应用程序的CSV文件中? I would offer compatibility from 2.3.3 to 4.2.2, so i wouldn't use library that cannot do this. 我会提供从2.3.3到4.2.2的兼容性,所以我不会使用不能这样做的库。 Can you help me wirte some code? 你能帮帮我一些代码吗? Thank you all!! 谢谢你们!!

Another thing..to export this file what permission i must add in manifest.xml? 另一件事......导出这个文件我必须在manifest.xml中添加什么权限?

You'll need to use a library such as opencsv (found here: http://sourceforge.net/projects/opencsv/ ) 您需要使用诸如opencsv之类的库(可在此处找到: 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<String[]> data = new ArrayList<String[]>();
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/ ) (从这里修改: http//viralpatel.net/blogs/java-read-write-csv-file/

to write a file to storage you will need the following permission: 要将文件写入存储,您需要以下权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM