2012-01-31 55 views
0

请看看下面的函数:上HTC渴望HD没有这样的表(在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是 “/数据/数据/ 应用程序包 /数据库/”。是否可以设置DB_PATH =“”?其实设置DB_PATH =“/ data/data/应用程序包/databases /”。在大多数设备上都能正常工作,但不适用于HTC渴望HD(讨论here,here,herehere)。该设备在设备上找不到上述路径。 感谢

回答

0

你应该设置你的DB_PATH这样的:

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

这会给你的完整路径数据库..然后你可以使用它作为您的outFileName

相关问题