我将本教程(http://www.screaming-penguin.com/node/7749)改编为我构建的Android应用程序,允许按下按钮将当前数据库导出到用户的SD卡.它完美无瑕.
但我担心我的应用程序的用户不熟悉db文件,我正在寻找一种方法将其转换为更加用户友好的格式.我遇到了这个主题(http://groups.google.com/group/android-beginners/browse_thread/thread/4e53ebca14daecfc),它建议“从数据库中查询数据并将数据写入csv文件”.
我希望有人能指出我正确的方向,开始弄清楚如何做到这一点.我发现很难找到有关特定方法的更多信息.
或者只是简单地解释如何阅读和访问.db文件更有意义?
谢谢
编辑:我也有一个关于sqlite导出过程的问题,我想我只是在这里问,而不是创建一个新的问题.有没有办法修改下面的代码,以便每个导出将接收日期的字符串表示或只附加一个数字?现在,如果您再次导出,它会自动覆盖旧文件.谢谢.
protected Boolean doInBackground(final String... args) {
File dbFile = new File(Environment.getDataDirectory() +
"/data/com.example.example/databases/data");
File exportDir = new File(Environment.getExternalStorageDirectory(), "exampledata");
if (exportDir.exists()) {
exportDir.mkdirs();
}
File file = new File(exportDir, dbFile.getName());
try {
file.createNewFile();
this.copyFile(dbFile, file);
return true;
} catch(IOException e) {
Log.e(MyApplication.APP_NAME, e.getMessage(), e);
return false;
}
}
解决方法:
I was hoping someone could point me in the right direction to begin figuring out how to do this.
要读入数据,请使用rawQuery().
要编写数据,请使用Java I/O.还有适用于Java的open source CSV libraries可用于Android.
Is there a way to modify the code below so that each export would receive either a string representation of the date or just a single numeral appended to it?
使用字符串连接将您想要的任何内容添加到文件名中.
另外,请摆脱:
File dbFile = new File(Environment.getDataDirectory() +
"/data/com.example.example/databases/data");
并替换为:
File dbFile=getDatabasePath("data");
原文地址:https://codeday.me/bug/20190705/1383044.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。