public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
copyDB();
setContentView(R.layout.activity_main);
func_spinner();
init();
}
private
void
copyDB() {
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+
"]"
);
}
}