尝试将数据库从assets-folder复制到数据库文件夹时的EISDIR

时间:2014-10-28 20:56:02

标签: java android sqlite filenotfoundexception

我正在尝试将我的数据库从assets-folder复制到数据库文件夹,但它无法正常工作,因为我收到了EISDIR-Error。我还从stackoverflow尝试了很多不同的解决方案,但我没有成功:

  1. 在启动(MainMenu.java)应用程序后调用的活动中,我创建了一个DBHelper对象(SQLiteConnect.java):

    SQLiteConnect db = new SQLiteConnect(this);
    
  2. SQLiteConnect类的构造函数(扩展SQLiteOpenHelper)正在执行以下操作:

    public SQLiteConnect(Context ccontext) {
        super(ccontext, DB_NAME, null, DB_VERSION);
        this.context = ccontext;
        this.dbFile = "database.sqlite";
        this.dbPath = this.context.getFilesDir().getAbsolutePath() + "/databases/";
        copyDataBase();     
    }
    
  3. copyDataBase()方法如下所示:

    public void copyDataBase() {
        System.out.println("Debuglog: Start Database Copy");
    
        byte[] buffer = new byte[1024];
        OutputStream myOutput = null;
        int length;
        InputStream myInput = null;
        try
        {
            myInput =this.context.getAssets().open(DB_NAME);
            String file = this.dbPath + this.dbFile;        
            myOutput =new FileOutputStream(file);
            while((length = myInput.read(buffer)) > 0)
            {
                myOutput.write(buffer, 0, length);
            }
            myOutput.close();
            myOutput.flush();
            myInput.close();
            System.out.println("Debuglog: Database Copy Finished");        
        }
        catch(Exception e)
        {
            System.out.println("Debuglog: Database Copy FAILED!");
            e.printStackTrace();
        }
    }
    
  4. 初始化OutputStream对象时,出现以下错误:

        10-28 21:39:12.811: W/System.err(16917): java.io.FileNotFoundException: /data/data/com.wwi12ama.szbeta/files/databases/database.sqlite: open failed: EISDIR (Is a directory)
    

    请询问您是否需要进一步的信息。非常感谢!

0 个答案:

没有答案