项目中需要把本地文件导入sqlite中,求高手给示例!搜了很多文档没找到合适答案。谢谢了
解决方案
10
可以存储在当前安装目录下,文件导入不到sqlite里面吧
10
先放到assert目录下,然后读取该文件,导入读取的内容到sqlite里面。讲的这么详细,网上很多教程的。
20
可以存储在当前安装目录下,文件导入不到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();
}
}