我有一堂课:
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;` }
第二类:
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; }
如何从我的应用程序将该信息保存到CSV文件中?我会提供从2.3.3到4.2.2的兼容性,所以我不会使用无法做到这一点的库。您能帮我写些代码吗?谢谢你们!!
另一件事..要导出此文件,必须在manifest.xml中添加什么权限?
您将需要使用诸如opencsv之类的库(可在此处找到:http : //sourceforge.net/projects/opencsv/)
要将数据写入文件,您需要执行以下操作:
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();
(从此处修改:http : //viralpatel.net/blogs/java-read-write-csv- file/)
要将文件写入存储,您将需要以下权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />