android读取已有的sqlite数据库到sdcard或ro
来源:互联网 发布:手机淘宝首页尺寸大小 编辑:程序博客网 时间:2024/05/22 16:53
package com.example.gdpuschedule;
import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import android.content.Context;import android.os.Environment;import android.util.Log;//此类获取sd卡路径!public class db_sacard_helper {public static final String DB_DIR = Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator+ "GDPUkebiao"; // + File.separator ;// + db_sacard_helper.class.getPackage().getName();public static String db_path = DB_DIR + File.separator + "mydb.db";private void writedb(Context context) throws IOException {// Log.i("sss", "文件开始创建" + dbsFile.mkdirs());// 判断数据库文件是否存在,若不存在则执行导入,否则直接打开数据库InputStream is = context.getResources().openRawResource(R.raw.mydb);// 输入的流FileOutputStream fos = new FileOutputStream(db_path);// 输出的流byte[] buffer = new byte[5000];int count = 0;while ((count = is.read(buffer)) > 0) {fos.write(buffer, 0, count);}fos.close();is.close();}public db_sacard_helper(Context context) throws IOException {if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {// 可读取sdcard// 创建目录File dbFolder = new File(DB_DIR);if (!dbFolder.exists()) {dbFolder.mkdirs();}// 创建文件File dbsFile = new File(db_path);if (!dbsFile.exists()) {writedb(context);Log.i("sss", "write db in sdcard");}else {Log.i("sss", "db in sdcard");}} else {// 不可读取sdcarddb_path = "/data"+ Environment.getDataDirectory().getAbsolutePath()+ File.separator+ db_sacard_helper.class.getPackage().getName()+ File.separator + "mydb.db";// 创建文件Log.i("sss", "db path::"+db_path);File dbsFile = new File(db_path);if (!dbsFile.exists()) {writedb(context);Log.i("sss", "create db in nei cun");}else {Log.i("sss", "db nei cun youle");}}}}
0 0
- android读取已有的sqlite数据库到sdcard或ro
- Android程序中读取使用已有的SQLite数据库
- android中访问已有的sqlite数据库
- android中访问已有的sqlite数据库
- Android导入已有的SQLite数据库
- Android加密已有的sqlite数据库---sqlcipher
- android -sqlite 从已有的.db文件创建数据库链接
- 如何在Android应用中使用已有的Sqlite数据库
- 在Android程序中使用已有的SQLite数据库
- 在Android程序中使用已有的SQLite数据库
- 在Android程序中使用已有的SQLite数据库
- 在Android程序中使用已有的SQLite数据库
- 在Android程序中使用已有的SQLite数据库
- Android使用已有的sqlite数据库的方法
- 用sqlcipher对已有的SQLite数据库加密
- [Android]如何导入已有的外部数据库
- [Android]如何导入已有的外部数据库
- [Android]如何导入已有的外部数据库
- 累一点没什么
- 六个国外免费DNS服务-做英文与外贸网站必备工具
- java多线程学习——CyclicBarrier
- 各种initcall的执行先后顺序(module_init、postcore_initcall、arch_initcall、subsys_initcall、 fs_initcall)
- Method Swizzling
- android读取已有的sqlite数据库到sdcard或ro
- 关于shader language中的matmxn和vecn
- UVA10887--Trie--哈希
- C#访问URL方法
- BZOJ 1208
- 【小细节】让sublime2可以在终端中打开
- Render to Texture2DArray slices in DirectX11?(转自GAMEDEV)
- 【marks】web前端资源
- C语言动态链表 取MP3歌词文件内容 带VC6.0完整工程