安卓项目中如何导入本地文件

sun__guy 2016-09-08 03:02:35
项目中需要把本地文件导入sqlite中,求大神给示例!!搜了很多文档没找到合适答案。谢谢了
...全文
368 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sun__guy 2016-09-10
  • 打赏
  • 举报
回复
引用 4 楼 qq_25412055 的回复:
[quote=引用 2 楼 sun__guy 的回复:] [quote=引用 1 楼 qq_25412055 的回复:] 可以存储在当前安装目录下,文件导入不到sqlite里面吧
是吗 我 刚学没多久!不太懂 那有没有示例呢??[/quote] 保存文件的话直接这个方法就行:
   public void copyFile(String oldPath, String newPath) {   
       try {   
           int bytesum = 0;   
           int byteread = 0;   
           File oldfile = new File(oldPath);   
           if (!oldfile.exists()) { //文件不存在时   
               InputStream inStream = new FileInputStream(oldPath); //读入原文件   
               FileOutputStream fs = new FileOutputStream(newPath);   
               byte[] buffer = new byte[1444];   
               int length;   
               while ( (byteread = inStream.read(buffer)) != -1) {   
                   bytesum += byteread; //字节数 文件大小   
                   System.out.println(bytesum);   
                   fs.write(buffer, 0, byteread);   
               }   
               inStream.close();   
           }   
       }   
       catch (Exception e) {   
           System.out.println("复制单个文件操作出错");   
           e.printStackTrace();   
  
       }   
  
   }  
[/quote] 恩 谢谢了!
sun__guy 2016-09-10
  • 打赏
  • 举报
回复
引用 3 楼 crash163 的回复:
[quote=引用 2 楼 sun__guy 的回复:] [quote=引用 1 楼 qq_25412055 的回复:] 可以存储在当前安装目录下,文件导入不到sqlite里面吧
是吗 我 刚学没多久!不太懂 那有没有示例呢??[/quote] 先放到assert目录下,然后读取该文件,导入读取的内容到sqlite里面。讲的这么详细,网上很多教程的。[/quote] 好的 谢谢!
一不小心_ 2016-09-08
  • 打赏
  • 举报
回复
引用 2 楼 sun__guy 的回复:
[quote=引用 1 楼 qq_25412055 的回复:] 可以存储在当前安装目录下,文件导入不到sqlite里面吧
是吗 我 刚学没多久!不太懂 那有没有示例呢??[/quote] 保存文件的话直接这个方法就行:
   public void copyFile(String oldPath, String newPath) {   
       try {   
           int bytesum = 0;   
           int byteread = 0;   
           File oldfile = new File(oldPath);   
           if (!oldfile.exists()) { //文件不存在时   
               InputStream inStream = new FileInputStream(oldPath); //读入原文件   
               FileOutputStream fs = new FileOutputStream(newPath);   
               byte[] buffer = new byte[1444];   
               int length;   
               while ( (byteread = inStream.read(buffer)) != -1) {   
                   bytesum += byteread; //字节数 文件大小   
                   System.out.println(bytesum);   
                   fs.write(buffer, 0, byteread);   
               }   
               inStream.close();   
           }   
       }   
       catch (Exception e) {   
           System.out.println("复制单个文件操作出错");   
           e.printStackTrace();   
  
       }   
  
   }  
网易云捕 2016-09-08
  • 打赏
  • 举报
回复
引用 2 楼 sun__guy 的回复:
[quote=引用 1 楼 qq_25412055 的回复:] 可以存储在当前安装目录下,文件导入不到sqlite里面吧
是吗 我 刚学没多久!不太懂 那有没有示例呢??[/quote] 先放到assert目录下,然后读取该文件,导入读取的内容到sqlite里面。讲的这么详细,网上很多教程的。
sun__guy 2016-09-08
  • 打赏
  • 举报
回复
引用 1 楼 qq_25412055 的回复:
可以存储在当前安装目录下,文件导入不到sqlite里面吧
是吗 我 刚学没多久!不太懂 那有没有示例呢??
一不小心_ 2016-09-08
  • 打赏
  • 举报
回复
可以存储在当前安装目录下,文件导入不到sqlite里面吧

80,492

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧