File dbFile = getDatabasePath("abook");
// AABDatabaseManager dbhelper = new
// AABDatabaseManager(getApplicationContext());
DBHandler dbhelper = new DBHandler(Suljung.this);
System.out.println(dbFile); // displays the data base
// path in your
// logcat
File exportDir = new File(
Environment.getExternalStorageDirectory(), "");
if (!exportDir.exists())
{
exportDir.mkdirs();
}
Date now = new Date();
SimpleDateFormat date = new SimpleDateFormat("yyyyMMddHHmm");
File file = new File("/sdcard/data/SB_backup/", "expense"
+ date.format(now) + ".csv");
try {
if (file.createNewFile()) {
System.out.println("File is created!");
System.out.println(file.getAbsolutePath());
} else {
System.out.println("File already exists.");
}
CSVWriter csvWrite = new CSVWriter(new FileWriter(file));
// SQLiteDatabase db =
// dbhelper.getWritableDatabase();
Cursor curCSV = dbhelper.all();
csvWrite.writeNext(curCSV.getColumnNames());
while (curCSV.moveToNext())
{
String arrStr[] = { curCSV.getString(0),
curCSV.getString(1), curCSV.getString(2),
curCSV.getString(3), curCSV.getString(4),
curCSV.getString(5), curCSV.getString(6),
curCSV.getString(7) };
/* curCSV.getString(3),curCSV.getString(4)}; */
csvWrite.writeNext(arrStr);
}
csvWrite.close();
curCSV.close();
코드를 이렇게 짜두었는데요.
엑셀로 확인 했을 때 한글이 다 깨지더라구요.
검색 해보니까
FileOutputStream fos = new FileOutputStream(file);
Writer out = new OutputStreamWriter(fos, "EUC-KR");
이 코드로 해결 하셨다는 분이 계시던데 저 코드를 어디에 적용 시켜야 되는지 모르겠어요ㅠㅠㅠㅠ