package
com.again.studyenglish1;
import
java.io.FileOutputStream;
import
java.io.IOException;
import
java.io.InputStream;
import
java.io.OutputStream;
import
java.util.*;
import
android.app.Activity;
import
android.database.sqlite.SQLiteDatabase;
import
android.database.sqlite.SQLiteException;
import
android.os.Bundle;
import
android.widget.TextView;
public
class
Activity_Three
extends
Activity {
private
static
String DB_PATH =
"/sdcard/"
;
private
static
String DB_NAME =
"dictionary.sqlite"
;
private
int
listcount =
0
;
private
String[] wordList =
null
;
private
String[] definitionList =
null
;
private
boolean
checkDatabase(){
SQLiteDatabase checkDB =
null
;
try
{
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath,
null
, SQLiteDatabase.OPEN_READONLY);
}
catch
(SQLiteException e){}
if
(checkDB !=
null
){checkDB.close();}
return
checkDB !=
null
?
true
:
false
;
}
private
void
copyDatabase()
throws
IOException{
InputStream myInput =
this
.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput =
new
FileOutputStream(outFileName);
byte
[] buffer =
new
byte
[
1024
];
int
total_length =
0
;
int
length;
while
((length = myInput.read(buffer))>
0
){
myOutput.write(buffer,
0
, length);
total_length+=length;
}
total_length+=length;
myOutput.flush();
myOutput.close();
myInput.close();
}
public
void
createDatabase()
throws
IOException{
boolean
dbExist = checkDatabase();
if
(dbExist){}
else
{
try
{
copyDatabase();
}
catch
(IOException e){
throw
new
Error(
"Error copying the Database"
);
}
}
}
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.wordtest);
}
TextView word = (TextView) findViewById(R.id.textView1);
}