android java 拷贝数据库文件到U盘,从U盘拷贝文件到私有目录下实现更新数据库文件

    private void copyDB(){
   
            File f = new File("/data/data/xxx/databases/xxx.db");
            File o = new File("/storage/udisk/xxx.db"); //sdcard上的目标地址
            if(f.exists()) {
                FileChannel outF;
                try {
                    outF = new FileOutputStream(o).getChannel();
                    new FileInputStream(f).getChannel().transferTo(0, f.length(),outF);
                    Toast.makeText(SplashActivity.this, "完成", Toast.LENGTH_SHORT).show();
                } catch (FileNotFoundException e) {
                    Toast.makeText(SplashActivity.this, "未检测到U盘", Toast.LENGTH_SHORT).show();
                    e.printStackTrace();
                } catch (IOException e) {
                    Toast.makeText(SplashActivity.this, "未检测到U盘", Toast.LENGTH_SHORT).show();
                    e.printStackTrace();
                }

            }

    }
    private void upgradeDB(){
            File f = new File("/storage/udisk/xxx.db"); 
            File o = new File("/data/data/xxx/databases/xxx.db"); //sdcard上的目标地址
            if(f.exists()) {
                FileChannel outF;
                try {
                    outF = new FileOutputStream(o).getChannel();
                    new FileInputStream(f).getChannel().transferTo(0, f.length(),outF);
                    Toast.makeText(SplashActivity.this, "完成", Toast.LENGTH_SHORT).show();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    Toast.makeText(SplashActivity.this, "未检测到U盘", Toast.LENGTH_SHORT).show();
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(SplashActivity.this, "未检测到U盘", Toast.LENGTH_SHORT).show();
                }
            }
    }

 

你可能感兴趣的:(JAVA,android)