放在数据库目录下啊
public final static String DB = Environment.getDataDirectory().getPath() + "/data/" + getPackageName() + "/databases/";public class SeiDbOpenHelper extends SQLiteOpenHelper { public final static String DB_NAME = "sei.db";
public final static int DB_VERSION = 2; public SeiDbOpenHelper(){
super(MainApplication.getContext(),DB_NAME,null,DB_VERSION);
} @Override
public void onCreate(SQLiteDatabase db) {
createDb(db);
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
} private static boolean checkIsDbExist(){
String fileName = Config.SystemFolder.DB + DB_NAME;
File file = new File(fileName);
return file.exists();
} private static void createDb(SQLiteDatabase db){
InputStream stream = null;
int size = 0;
try {
stream = MainApplication.getContext().getResources().getAssets().open("sei.db");
size = stream.available();
} catch (IOException e) {
Log.e("",e.getMessage());
e.printStackTrace();
}
if(size > 0){
File dir = new File(Config.SystemFolder.DB);
if(!dir.exists())
dir.mkdir();
String dbPath = Config.SystemFolder.DB + DB_NAME;
File file = new File(dbPath); //替换原有数据库,系统好像会自动生成一个!
if(file.exists()){
if(file.length() > 24*1024){
//非空数据库,备份
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String backdbName = "autoback_c_v" + String.valueOf(DB_VERSION) + "_" + formatter.format(new Date()) + ".db";
backDb(null,backdbName,DB_VERSION);
}
file.delete();
} if(!file.exists())
{
try {
FileOutputStream writer = new FileOutputStream(dbPath);
FileHelper.CopyFile(stream,writer);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(stream != null)
{
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public final static String DB = Environment.getDataDirectory().getPath() + "/data/" + getPackageName() + "/databases/";public class SeiDbOpenHelper extends SQLiteOpenHelper { public final static String DB_NAME = "sei.db";
public final static int DB_VERSION = 2; public SeiDbOpenHelper(){
super(MainApplication.getContext(),DB_NAME,null,DB_VERSION);
} @Override
public void onCreate(SQLiteDatabase db) {
createDb(db);
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
} private static boolean checkIsDbExist(){
String fileName = Config.SystemFolder.DB + DB_NAME;
File file = new File(fileName);
return file.exists();
} private static void createDb(SQLiteDatabase db){
InputStream stream = null;
int size = 0;
try {
stream = MainApplication.getContext().getResources().getAssets().open("sei.db");
size = stream.available();
} catch (IOException e) {
Log.e("",e.getMessage());
e.printStackTrace();
}
if(size > 0){
File dir = new File(Config.SystemFolder.DB);
if(!dir.exists())
dir.mkdir();
String dbPath = Config.SystemFolder.DB + DB_NAME;
File file = new File(dbPath); //替换原有数据库,系统好像会自动生成一个!
if(file.exists()){
if(file.length() > 24*1024){
//非空数据库,备份
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String backdbName = "autoback_c_v" + String.valueOf(DB_VERSION) + "_" + formatter.format(new Date()) + ".db";
backDb(null,backdbName,DB_VERSION);
}
file.delete();
} if(!file.exists())
{
try {
FileOutputStream writer = new FileOutputStream(dbPath);
FileHelper.CopyFile(stream,writer);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(stream != null)
{
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
解决方案 »
- Android Socket 编程与服务器通信的问题
- ListView 刷新后点击无响应问题,希望了解的高手解答一下
- Android中Service传递数据到Activity?
- android 怎么实现触摸屏校正
- eclipse里面没有SharedPreferences?是不是我没下载到呀?那位大侠给我传一个呀?
- 子线程如何异步更新Fragment的UI界面
- activity的切换动画里,进入的activity动画怎么不覆盖掉退出的activity动画
- android 点击操作的切换 onclick操作
- android token失效问题
- ANDROID如何设置移动专网APN
- 关于APP的调用webService的问题
- Fragment跳转返回控制问题
如果数据库文件很大,可以采用切割文件,复制完成后重新合并文件。 Google “android 附加 数据库”,有解决方案