android资源文件的路径(String)

时间:2014-09-18 17:48:47

标签: java android eclipse

我在资产文件夹中有一个数据库文件。我想要这个文件的路径。我必须为我的方法参数放置什么路径(字符串)?

提前谢谢

1 个答案:

答案 0 :(得分:0)

将您的数据库放入src / main / assets文件夹dbname.db

并使用此代码

private static String DB_NAME = "dbname.db";
private static String DB_PATH = "";
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";


private void copyDataBase() throws IOException{
        AssetManager assets = mContext.getAssets();
        InputStream mInput = assets.open("hashvetar.db");
        String outFileName = DB_PATH + DB_NAME;
        OutputStream mOutput = new FileOutputStream(outFileName);
        byte[] mBuffer = new byte[1024];
        int mLength;
        while ((mLength = mInput.read(mBuffer))>0)
        {
           mOutput.write(mBuffer, 0, mLength);
        }
        mOutput.flush();
        mOutput.close();
        mInput.close();
}