How to copy database file from asset folder to /data/data/<package-name>/database folder
<p>I have put a database file in to assets folder and want to copy it to /data/data//database folder . For this purpose , I have written the following code : </p>

<pre><code>public void copy()
{
    try
    {
        String dest_path = "/data/data/"+getPackageName()+"/database/sultandatabase";
        File f = new File(dest_path);
        if( !f.exists() )
        {
            copy_database(getBaseContext().getAssets().open(db_name),new FileOutputStream(dest_path));
        }
    }
    catch(Exception e)
    {
        Toast.makeText(this,"Sorry the file can not be opended", Toast.LENGTH_LONG).show();

    }
}

public void copy_database(InputStream io ,OutputStream ou) throws Exception
{
    byte[] buffer = new byte[1024] ;
    int lenght;

    while( ( lenght = io.read(buffer)) &gt; 0 )
        ou.write(buffer);
    io.close();
    ou.close();

}
</code></pre>

<p>When I call copy() the database file is not copied . What is the possible reason ?? How can I fix this ??  Instead a toast is shown up . That means my program gets Exception ?? But why ?? </p>
