HTC desire HD(Android上的SQLite数据库)上没有这样的表
请查看以下功能:HTC desire HD(Android上的SQLite数据库)上没有这样的表,android,sqlite,Android,Sqlite,请查看以下功能: private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
File f = new File(DB_PATH);
if (!f.exists()) {
f.mkdir();
}
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
//myInput.read(buffer);
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
其中DB_路径为“/data/data/application package/databases/”。是否可以设置DB_PATH=“”?实际设置DB_PATH=“/data/data/application package/databases/”。在大多数设备上工作正常,但在HTC desire HD上不起作用(已讨论、和)。此设备在设备上找不到提到的路径。
谢谢您应该这样设置
DB\u路径
:
String DB_PATH = context.getDatabasePath(DB_NAME).getAbsolutePath()
这将为您提供数据库的完整路径。。然后您可以将其用作您的输出文件名