【问题标题】:No such table on HTC desire HD (SQLite database on Android)HTC 渴望 HD 上没有这样的表(Android 上的 SQLite 数据库)
【发布时间】:2012-01-31 17:37:16
【问题描述】:

请看下面的函数:

 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)。此设备在设备上找不到提到的路径。 谢谢

【问题讨论】:

    标签: android sqlite


    【解决方案1】:

    你应该像这样设置你的DB_PATH

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      相关资源
      最近更新 更多