android sqlite 打包 xe,导入/导出到Android的SQLite数据库

我见过一些关于如何导入和导出数据库在Android的帖子,我发现这些代码,但我似乎无法使它的工作。我得到错误java.io.filenotfoundexception/storage/sdcard0/BackupFolder/DatabaseName:打开失败的ENOENT(没有这样的文件或目录)。香港专业教育学院改变了一些东西,但我仍然没有得到文件中发现异常导入/导出到Android的SQLite数据库

这里是我的出口:

private void exportDB() {

try {

db.open();

File newFile = new File("/sdcard/myexport");

InputStream input = new FileInputStream(

"/data/data/com.example.mycarfuel/data

bases/MyDatabase");

OutputStream output = new FileOutputStream(newFile);

byte[] buffer = new byte[1024];

int length;

while ((length = input.read(buffer)) > 0) {

output.write(buffer, 0, length);

}

output.flush();

output.close();

input.close();

db.close();

} catch (FileNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

和我的导入:

private void importDB() {

try {

File sd = Environment.getExternalStorageDirectory();

File data = Environment.getDataDirectory();

if (sd.canWrite()) {

String currentDBPath = "//data//" + "PackageName"

+ "//databases//" + "DatabaseName";

String backupDBPath = "/BackupFolder/DatabaseName

";

File backupDB = new File(data, currentDBPath);

File currentDB = new File(sd, backupDBPath);

FileChannel src = new FileInputStream(currentDB).getChannel();

FileChannel dst = new FileOutputStream(backupDB).getChannel();

dst.transferFrom(src, 0, src.size());

src.close();

dst.close();

Toast.makeText(getBaseContext(), backupDB.toString(),

Toast.LENGTH_LONG).show();

}

} catch (Exception e) {

Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG)

.show();

}

}

+0

请按照[此链接](http://stackoverflow.com/a/6542214/2345913) –

2013-05-14 07:14:55

+0

我看过这篇文章。第二个答复是从哪里复制我的代码,第一个答复只说关于导入不导出 –

2013-05-14 07:22:32

+0

请检查此链接,它可以解决此问题: http://stackoverflow.com/questions/6540906/simple-export- And-import-of-a-sqlite-database-on-android –

2016-01-19 07:55:37

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值