android将asseet当中的数据库文件拷到程序目录
2015-04-17 18:11
363 查看
/** * 将asseet当中的数据库文件拷到程序目录 * @param activity 当前Activity * @param filePath 你的程序目录 getApplicationContext().getFilesDir().getAbsolutePath(); * @param fileName 你的数据库名称 */ public static void copyEmbassy2Databases(Activity activity, String filePath, String fileName) { System.out.println("-->copyEmbassy2Databases"); File oldfile = new File(filePath, fileName); if (oldfile.exists()) oldfile.delete(); File file = new File(filePath, fileName); if (file.exists()) return; file.getParentFile().mkdirs(); InputStream in = null; OutputStream out = null; try { out = new FileOutputStream(file); byte[] buff = new byte[1024]; int len = 0; in = activity.getAssets().open(fileName); while ((len = in.read(buff)) > 0) { out.write(buff, 0, len); } out.flush(); in.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (out != null) out.close(); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- Android学习之查找程序根目录下的所有文件
- Android--查找程序根目录下所有文件/Java IO操作
- Android--查找程序根目录下所有文件/Java IO操作
- 【Android小范例教程】【1】查找程序根目录下的文件
- 现在我要写一个定时程序定时读取该目录下的所有txt文件到数据库,并把这些txt文件转移到另外一个目录
- Android获取系统文件目录,让程序访问其他程序的/data/data下的私有文件
- android中如何读取已经在sqlite expert professional等sqlite工具设计好的数据库文件并且在程序中创建数据库
- 通过assets向安卓程序目录中导入数据库文件出现错误的解决办法
- Android拷贝压缩文件到程序目录
- Android中打开raw目录下的数据库文件
- Android编程实现将压缩数据库文件拷贝到安装目录的方法
- 解决:Android使用自带sqlite开发时,apk中创建的数据库外部的进程是没有权限去读/写的,而且无法如何读取指定目录下的db文件
- Android编程实现将压缩数据库文件拷贝到安装目录的方法
- android 打开 res raw目录 中 数据库文件
- android私有存储目录下的文件如何让其他程序有权限打开
- 之前账号的文章3:android私有存储目录下的文件如何让其他程序有权限打开
- Android查看手机内部储存目录及数据库文件
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
- 如何在android应用程序中拷贝第三方资产目录下的数据库文件到应用私有目录下
- 程序数据库PDB调试文件