private void copyDBToSDcrad()
{
String DATABASE_NAME = "数据库文件名"; String oldPath = "data/data/com.packagename/databases/" + DATABASE_NAME;
String newPath = Environment.getExternalStorageDirectory() + File.separator + DATABASE_NAME; copyFile(oldPath, newPath);
} /**
* 复制单个文件
*
* @param oldPath
* String 原文件路径
* @param newPath
* String 复制后路径
* @return boolean
*/
public static void copyFile(String oldPath, String newPath)
{
try
{
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
File newfile = new File(newPath);
if (!newfile.exists())
{
newfile.createNewFile();
}
if (oldfile.exists())
{ // 文件存在时
InputStream inStream = new FileInputStream(oldPath); // 读入原文件
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
while ((byteread = inStream.read(buffer)) != -1)
{
bytesum += byteread; // 字节数 文件大小
fs.write(buffer, 0, byteread);
}
inStream.close();
}
}
catch (Exception e)
{
System.out.println("复制单个文件操作出错");
e.printStackTrace(); } }

将android程序中的数据库导出到SD卡的更多相关文章

  1. 在Android程序中使用已有的SQLite数据库

    已经将这篇文章迁移至 Code问答,你也能够到这里查看这篇文章,请多多关注我的新技术博客CodeWenDa.com 在中文搜索中,没有找到一篇比較好的关于怎样在Android应用中使用自己事先创建好的 ...

  2. XamarinSQLite教程在Xamarin.Android项目中使用数据库

    XamarinSQLite教程在Xamarin.Android项目中使用数据库 在Xamarin.Android项目中使用预设数据库的具体操作步骤如下: (1)创建一个Xamarin.Android项 ...

  3. SQLite在Android程序中的使用方法,SQLite的增删查改方法

    Sqlite: 1.一款用来实现本地数据存储的轻量级数据管理工具,是众多用来实现数据库管理的工具之一. 2.Android已经将SQLite的代码功能吸收在它的系统中,我们可以直接在Android程序 ...

  4. C#程序中从数据库取数据时需注意数据类型之间的对应,int16\int32\int64

    private void btn2_Click(object sender, RoutedEventArgs e)         {             using (SqlConnection ...

  5. android 程序中res/values-v14/styles.xml报错的解决办法

    从旧的ADT迁移的新的ADT时, android 程序中res/values-v14/styles.xml报错: error: Error retrieving parent for item: No ...

  6. 【转】如何在 Android 程序中禁止屏幕旋转和重启Activity

    原文网址:http://www.cnblogs.com/bluestorm/p/3665890.html 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...

  7. XamarinSQLite教程在Xamarin.Android项目中提取数据库文件

    XamarinSQLite教程在Xamarin.Android项目中提取数据库文件 由于不能直接打开该文件,开发者需要先将数据库文件从Android系统中提取出来.操作步骤如下. (5)选择MyDoc ...

  8. XamarinSQLite教程在Xamarin.Android项目中定位数据库文件

    XamarinSQLite教程在Xamarin.Android项目中定位数据库文件 实际开发中,经常需要验证数据库操作的正确性.这个时候,需要打开数据库文件,进行确认.下面是如何找到MyDocumen ...

  9. 【转】在android程序中使用配置文件properties

    在android程序中使用配置文件来管理一些程序的配置信息其实非常简单 在这里我们主要就是用到Properties这个类直接给函数给大家 这个都挺好理解的 读写函数分别如下: //读取配置文件 pub ...

随机推荐

  1. ruby,python及curl post请求

    #飘红部分为变量 test_url="http://test" body_hash={"value"=>100, "year"=> ...

  2. 关于Java Collections的几个常见问题

    列举几个关于Java Collections的常见问题并给出答案. 1. 什么时候用LinkedList,什么时候用ArrayList? ArrayList是使用数组实现的list,本质上就是数组.A ...

  3. 用一个for循环实现打印乘法口诀表

    本博客不再更新,很多其它精彩内容请訪问我的独立博客 循环体内定义两个变量.一个控制列,一个控制行. for(int i=0,j=0;j<9;i++){ System.out.println(j+ ...

  4. hdoj1251 统计难题 字典树

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  5. python文件和目录操作方法大全

    一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd()2.返回指定目录下的所有文件和 ...

  6. Map Class Example

    Here's a quick look at how to use the Scala Map class, with a colllection of Map class examples. The ...

  7. fileupload 上传execl文件的一些操作

    OABaseReadExeclDataAction .class 包含创建临时文件目录,基本校验,取属性值,处理乱码,基类 这里在上传文件是execl并且需要读取的话,需要把fileitem对象转换成 ...

  8. c++之——template模板函数

    为了实现与数据类型无关的编程,模板应运而生: #include<iostream> #include<string.h> using namespace std; templa ...

  9. How To Install and Configure Elasticsearch on Ubuntu 14.04

    Reference: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsear ...

  10. Java中常见的异常__

    作为一名游戏开发者,程序员,很自然必须熟悉对程序的调试方法.而要调试程序,自然需要对程序中的常见的异常有一定的了解,这些日子很多朋友都提出了很多问题,都是关于游戏中的报错,因此在这里我将一些常见的程序 ...