导出从应用程序的Andr​​oid我的CSV文件数据 [英] Export my data on CSV file from app android

查看:168
本文介绍了导出从应用程序的Andr​​oid我的CSV文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类:

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,所以我不会用库,无法做到这一点。你能帮我WIRTE一些code?谢谢大家!

How can i do to save this information into a CSV file from my app? I would offer compatibility from 2.3.3 to 4.2.2, so i wouldn't use library that cannot do this. Can you help me wirte some code? Thank you all!!

另外thing..to导出该文件的权限是什么,我必须在manifest.xml的增加?

Another thing..to export this file what permission i must add in manifest.xml?

推荐答案

您需要使用的库如opencsv(这里找到:的 http://sourceforge.net/projects/opencsv/

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<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();

(修改从这里开始:<一href="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" />

这篇关于导出从应用程序的Andr​​oid我的CSV文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆