String filename =filename();initData(filename);
@Suppresslint("SimpleDateFormat")public voID initData(String f1) { file f = new file(f1); if (f.exists()) { f.delete(); } file = new file(getSdpath() + "/Scan"); makeDir(file); TxtUtils.writeTxt(f1,"条码"+" "+"数量"+"\n"); //将从数据库中读取的数据写入txt文件中 cursor = databaSEOperation.query_db(); if(cursor.movetoFirst()){ do{ String code=cursor.getString(cursor.getColumnIndex("code")); String num=cursor.getString(cursor.getColumnIndex("num")); TxtUtils.writeTxt(f1,code+","+" "+num+"\n"); }while (cursor.movetoNext()); }}
public static voID makeDir(file dir) { if (!dir.getParentfile().exists()) { makeDir(dir.getParentfile()); } dir.mkdir();}
public static voID writeTxt(String filename,String content) { try { //要指定编码方式,否则会出现乱码 OutputStreamWriter osw = new OutputStreamWriter(new fileOutputStream(filename,true),"gbk"); osw.write(content); osw.close(); } catch (IOException e) { e.printstacktrace(); }}
private String filename(){ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-hh-mm"); String date=sdf.format(new java.util.Date()); String filename="/mnt/sdcard/Scan/"+date+".txt"; return filename;}public String getSdpath() { file sdDir = null; boolean sdCardExist = Environment.getExternalStorageState().equals( androID.os.Environment.MEDIA_MOUNTED); if (sdCardExist) { sdDir = Environment.getExternalStorageDirectory(); } String dir = sdDir.toString(); return dir;}
总结 以上是内存溢出为你收集整理的将SQlite中的数据以txt文件导出全部内容,希望文章能够帮你解决将SQlite中的数据以txt文件导出所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)