【发布时间】:2015-07-16 17:49:22
【问题描述】:
这是我将数据库从资产文件夹复制到 SD 卡的代码:
File databaseFile = new File(context.getExternalFilesDir(null),"");
if(!databaseFile.exists()){
databaseFile.mkdirs();
}
String outFileName = context.getExternalFilesDir(null) + "/db.db";
try {
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
InputStream myInput = context.getAssets().open("db");
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myInput.close();
myOutput.flush();
myOutput.close();
} catch (Exception e) {
Log.v("this",e.getMessage().toString());
}
当我运行它时,它给了我这个错误:
/storage/emulated/0/Android/data/myPackageName/files/db.db: open failed: EISDIR (Is a directory)
我该如何解决这个问题? 我已经阅读了这个主题,但没有工作: FileOutputStream crashes with "open failed: EISDIR (Is a directory)" error when downloading image
另外,我在读取设备上测试它,同样的错误 谢谢
【问题讨论】:
-
检查这应该对您有所帮助:stackoverflow.com/a/12339821/6947002