package study.DBTEST;
import java.io.*;
import android.app.Activity;
import android.content.*;
import android.content.res.*;
import android.database.*;
import android.database.sqlite.*;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
public class DBTEST extends Activity {
EditText mText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
findViewById(R.id.btn_ac).setOnClickListener(mClickListener);
findViewById(R.id.btn_ca).setOnClickListener(mClickListener);
DBUPLOAD();//DBUP
}
Button.OnClickListener mClickListener = new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(DBTEST.this,ListQ.class);
Bundle Reg = new Bundle();
switch (v.getId())
{
case R.id.btn_ac:
Reg.putInt("SelectQ", 1);//A-C
intent.putExtras(Reg);
startActivity(intent);
break;
case R.id.btn_ca:
Reg.putInt("SelectQ", 2);//C-A
intent.putExtras(Reg);
startActivity(intent);
}
}
};
public void DBUPLOAD()
{
AssetManager am =null;
InputStream[] arrIs = new InputStream[1];
BufferedInputStream[] arrBis = new BufferedInputStream[1];
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try
{
File f = new File("/data/data/study.DBTEST/databases/timetables.db");
if(f.exists())
{
f.delete();
f.createNewFile();
}
am=this.getResources().getAssets();
for(int i = 0; i < arrIs.length; i++)
{
arrIs[i] = am.open("dbs/timetables.db");
arrBis[i] = new BufferedInputStream(arrIs[i]);
}
fos = new FileOutputStream(f);
bos = new BufferedOutputStream(fos);
int read = -1;
byte[] buffer = new byte[1024];
for(int i = 0; i < arrIs.length; i++)
{
while((read = arrBis[i].read(buffer, 0, 1024)) != -1)
{
bos.write(buffer, 0, read);
}
bos.flush();
}
}
catch(Exception e){}
}
}