我在资产文件夹中有一个数据库文件。我想要这个文件的路径。我必须为我的方法参数放置什么路径(字符串)?
提前谢谢
答案 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();
}