没有关于HTC欲望HD的这样的表格(Android上的SQLite数据库)

时间:2012-01-31 17:37:17

标签: 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_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_PATH是“/ data / data / 应用程序包 / databases /”。是否可以设置DB_PATH =“”?实际设置DB_PATH =“/ data / data / 应用程序包 / databases /”。在大多数设备上工作正常,但不适用于HTC欲望HD(讨论herehereherehere)。此设备在设备上找不到上述路径。 感谢

1 个答案:

答案 0 :(得分:0)

您应该像这样设置DB_PATH

String DB_PATH = context.getDatabasePath(DB_NAME).getAbsolutePath()

这将为您提供数据库的完整路径..然后您可以将其用作outFileName