Android开发之获取assets文件夹中的数据库内容并写入到SD卡中
2015-06-17 11:22
246 查看
import java.io.File; |
02 | import java.io.FileOutputStream; |
03 | import java.io.IOException; |
04 | import java.io.InputStream; |
05 | import android.content.Context; |
06 | /*将assets文件夹下的数据库写入SD卡中 |
07 | * |
08 | public class WriteToSD |
09 | private Context |
10 | String "/mytest" ; |
11 | public WriteToSD(Context |
12 | this .context |
13 | if (!isExist()){ |
14 | write(); |
15 | } |
16 | } |
17 | private void write(){ |
18 | InputStream |
19 | try { |
20 | inputStream "city.db" ); |
21 | File new File(filePath); |
22 | if (!file.exists()){ |
23 | file.mkdirs(); |
24 | } |
25 | FileOutputStream new FileOutputStream(filePath "/database.db" ); |
26 | byte [] new byte [ 512 ]; |
27 | int count 0 ; |
28 | while ((count 0 ){ |
29 | fileOutputStream.write(buffer, 0 ,count); |
30 | } |
31 | fileOutputStream.flush(); |
32 | fileOutputStream.close(); |
33 | inputStream.close(); |
34 | System.out.println( "success" ); |
35 | } catch (IOException |
36 | e.printStackTrace(); |
37 | } |
38 | } |
39 | private boolean isExist(){ |
40 | File new File(filePath "/database.db" ); |
41 | if (file.exists()){ |
42 | return true ; |
43 | } else { |
44 | return false ; |
45 | } |
46 | } |
47 | } |
相关文章推荐
- Android fill_parent、wrap_content和match_parent的区别
- android studio 快捷键
- android 点击 textview 显示和隐藏 的切换
- Android Xfermode 实战 实现圆形、圆角图片
- Android资源使用详解(二)
- Android中的Interpolator
- Android动画学习笔记-Android Animation
- Android 如何判断一个应用在运行
- Android Studio程序中setText出现中文乱码
- Android GridView属性集合
- Android出现“R cannot be resolved to a variable"
- Android实现用户引导界面
- Android Fragment管理类,操作Fragment的增加、删除、替换、隐藏、显示等
- Android学习【Activity界面跳转】
- Android Activity管理类,管理Activity和退出应用
- Java(Android)线程池
- Android开发:Android设备传感器开发总结
- Android兼容性测试的一些坑
- Android Lint 检查规则列表
- Android内存性能优化(内部资料总结)