您还可以将文件放在原始资源 (/res/raw) 文件夹中并使用此标准功能:
protected void CopyResource(int aInputIDResource, String aOutputFileName, boolean afForceWrite) {
if (afForceWrite == false) {
InputStream theTestExist;
try {
theTestExist = openFileInput(aOutputFileName);
theTestExist.close();
return;
} catch (IOException e) {
}
}
char[] theBuffer = new char[1024];
int theLength;
try {
OutputStreamWriter out = new OutputStreamWriter(openFileOutput(
aOutputFileName, MODE_WORLD_READABLE), "ISO-8859-1");
InputStreamReader in = new InputStreamReader(getResources()
.openRawResource(aInputIDResource), "ISO-8859-1");
while ((theLength = in.read(theBuffer)) > 0)
out.write(theBuffer, 0, theLength);
out.flush();
out.close();
} catch (Exception e) {
Log.e("TAG", "Error: " + e.getMessage());
}
}
然后在您的应用程序或活动的 onCreate() 函数中,调用:
CopyResource(R.raw.your_database, "MR_SBusPlugin.so", false);