Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int cursorToCSV(Cursor cursor, String file)
- {
- // TODO Auto-generated method stub
- StringBuffer out = new StringBuffer();
- int count=0;
- // loop thru all the records
- while (cursor.moveToNext())
- {
- // loop thru all the columns
- for (int i = 0; i < cursor.getColumnCount(); i++)
- {
- String column = cursor.getString(i);
- if (i != 0)
- out.append(",");
- out.append(column); // adds a column
- }
- out.append("\n");
- count++;
- }
- // save to a file
- try
- {
- FileOutputStream outStream = context.openFileOutput(file, Context.MODE_PRIVATE);
- outStream.write(out.toString().getBytes());
- outStream.close();
- Log.d("Backup", out.toString());
- } catch (IOException e)
- {
- Log.d("Backup", "Error writing CSV to file: "+file); e.printStackTrace();
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement