安卓项目中怎么样导入本地文件

Android 码拜 8年前 (2016-09-25) 1035次浏览
项目中需要把本地文件导入sqlite中,求高手给示例!搜了很多文档没找到合适答案。谢谢了
解决方案

10

可以存储在当前安装目录下,文件导入不到sqlite里面吧

10

引用:
Quote: 引用:

可以存储在当前安装目录下,文件导入不到sqlite里面吧

是吗 本人 刚学没多久!不太懂 那有没有示例呢?

先放到assert目录下,然后读取该文件,导入读取的内容到sqlite里面。讲的这么详细,网上很多教程的。

20

引用:
Quote: 引用:

可以存储在当前安装目录下,文件导入不到sqlite里面吧

是吗 本人 刚学没多久!不太懂 那有没有示例呢?

保存文件的话直接这个方法就行:

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

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明安卓项目中怎么样导入本地文件
喜欢 (0)
[1034331897@qq.com]
分享 (0)