這是我的代碼,當我運行它不存儲或生成任何文件在我的SD卡。我不明白我在做節目的錯誤道歉的錯誤,因爲IM初學者Sqlite數據到Android中的CSV文件
List<ClientModel> list = new ArrayList<ClientModel>(); //My Model
DatabaseHelper db = new DatabaseHelper(getApplicationContext()); //My DBHelper Class
list = db.getAllClientList(); //My Method to get all data from database
File exportDir = new File(Environment.getExternalStorageDirectory(), ""); //
if (!exportDir.exists())
{
exportDir.mkdirs();
}
File file = new File(exportDir, "Abc.csv"); //File Name
//writing data to a txt file
try {
file.createNewFile();
CSVWriter csvWrite = new CSVWriter(new FileWriter(file)); //Writing data in csv file
for (int index = 0; index < list.size();) {
String arrStr[] = { String.valueOf(list.get(0))};
csvWrite.writeNext(arrStr);
}
csvWrite.close();
//But Above Code is not working for me
} catch (IOException e) {
e.printStackTrace();
}
你有沒有在manifest中寫入權限? –
是的,我已經添加了 –
Cool
什麼錯誤接收'catch'塊? – rafsanahmad007