private void copyDB() {
// TODO Auto-generated method stub
String PACKAGE_DIR = "/data/data/app.smtit_yd/";
String DATABASE_NAME = "TimeTable.db";
File folder = new File(PACKAGE_DIR);
if (folder.exists()){
} else {
folder.mkdirs();
}
AssetManager A_man = getResources().getAssets();
File ofile = new File(PACKAGE_DIR + "databases/" + DATABASE_NAME);
ofile.delete();
InputStream in = null;
FileOutputStream out = null;
long filesize = 0;
try{
in = A_man.open(DATABASE_NAME,AssetManager.ACCESS_BUFFER);
filesize = in.available();
if(ofile.length() <=0){
byte[] tmpbyte = new byte[(int)filesize];
in.read(tmpbyte);
in.close();
ofile.createNewFile();
out = new FileOutputStream(ofile);
out.write(tmpbyte);
out.close();
}else{
System.out.println("DB있음!!!");
}
}catch(IOException e){
System.out.println("DB생성 오류 ["+e+"]");
}
}
DB를 카피하는 코드입니다. 그런데 이게 apk를 뽑아서 설치 했을경우 완전 최초 설치 후 실행할 경우 DB를 못 뿌려줍니다.
그다음에 어플을 종료하고 그 다음에 실행시에는 DB를 뿌려주는데 왜 최초실행시에만 DB를 사용하지 못할까요?