首页 > 移动平台 > 详细

android将asseet当中的数据库文件拷到程序目录

时间:2015-04-17 20:14:28      阅读:141      评论:0      收藏:0      [点我收藏+]
/**
         * 将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将asseet当中的数据库文件拷到程序目录

原文:http://www.cnblogs.com/spadd/p/4435672.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!