zoukankan      html  css  js  c++  java
  • 将android程序中的数据库导出到SD卡

    	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();
    
    		}
    
    	}

  • 相关阅读:
    Razor使用方法
    Razor视图中的@:和<text>语法
    【洛谷p1031】均分纸牌
    Python读写文件
    对象传参数中引用是否被覆盖的情形
    Python中的random模块
    mysql数据库 安装 (原创)
    MYSQL常用命令
    MySQL查询数据表中数据记录(包括多表查询)
    127.0.0.1
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/6738447.html
Copyright © 2011-2022 走看看