`
wang_peng1
  • 浏览: 3905685 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

db数据库的处理

OS 
阅读更多

final String DB_DESTINATION = "/data/data/YOUR_PACKAGE_NAME/databases/MyDatabaseFile.db"; 
 
// Check if the database exists before copying 
boolean initialiseDatabase = (new File("DB_DESTINATION")).exists(); 
if (initialiseDatabase == true) { 
 
   
// Open the .db file in your assets directory 
   
InputStream is = getContext().getAssets().open("MyDatabaseFile.db"); 
 
   
// Copy the database into the destination 
   
OutputStream os = new FileOutputStream(DB_DESTINATION); 
   
byte[] buffer = new byte[1024]; 
   
int length; 
   
while ((length = is.read(buffer)) > 0){ 
        os
.write(buffer, 0, length); 
   
} 
    os
.flush(); 
 
    os
.close(); 
   
is.close(); 
} 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics