文档介绍:
这是一个Android范例,兹说明如下:
Step-1: ,如下:
程序一开始执行,建立一个数据库,含有BLOB字段,如下之指令:
sql = "create table mySong("
+ "song_no text not null, "
+ "song_mp3 blob );";
try {
(sql);
} catch (SQLException e) {
("ERROR", ());
return;
}
Step-2: 从Project的/res/raw/读取*.mp3歌曲,然后分段储存到SQLite的BLOB里,如下之指令:
InputStream is = getResources().openRawResource(rid);
int bufSize = 63*1024;
byte[] buffer = new byte[bufSize];
try {
int size = (buffer);
while(size >= 0){
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
(buffer, 0, size);
();
();
("song_mp3", ());
("mySong", null, cv);
size = (buffer);
}
} catch (IOException e) {
("ERROR", ());
}
Step-3: 从SQLite的BLOB里,读取歌曲并存入
/data/.,
如下之指令:
FileOutputStream os = null;
try{
os = openFileOutput("", MODE_WORLD_READABLE);
} catch(FileNotFoundException e){
("ERROR", ());
}
byte[] red_buf;
//----------------------------------------
mOpenHelper = new DatabaseHelper(this);
SQLiteDatabase db = ();
String col[] = {"song_no", "song_mp3" };
cur = ("mySong", col, cond, null, null, null, null);
int k =0;
();
try{
while