You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@osiegmar
Unable to save to csv due to exception, below is my stack trace and my code.
No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File;
if (entityList.size() > 0) {
File storageDir = new File(Environment.getExternalStorageDirectory() + "/"
+ this.getString(R.string.app_name));
boolean success = true;
if (!storageDir.exists()) {
success = storageDir.mkdirs();
}
if (success) {
// String baseDir = getExternalStorageDirectory().getAbsolutePath();
// String filePath = baseDir + "/" + "Demo.csv";
File file = new File(storageDir, "contacts.csv");
CsvWriter csvWriter = new CsvWriter();
Collection<String[]> data = new ArrayList<>();
for (ContactEntity d : entityList) {
data.add(new String[]{"Name", "Phone Number"});
data.add(new String[]{d.getName(), d.getName()});
}
try {
csvWriter.write(file, StandardCharsets.UTF_8, data);
Log.v(TAG, "csv file created");
} catch (IOException e) {
e.printStackTrace();
}
}else {
Toast.makeText(this, "Directory not exist", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "No data to export csv", Toast.LENGTH_SHORT).show();
}
The text was updated successfully, but these errors were encountered:
@osiegmar
Unable to save to csv due to exception, below is my stack trace and my code.
No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File;
if (entityList.size() > 0) {
// String baseDir = getExternalStorageDirectory().getAbsolutePath();
// String filePath = baseDir + "/" + "Demo.csv";
File file = new File(storageDir, "contacts.csv");
CsvWriter csvWriter = new CsvWriter();
Collection<String[]> data = new ArrayList<>();
for (ContactEntity d : entityList) {
data.add(new String[]{"Name", "Phone Number"});
data.add(new String[]{d.getName(), d.getName()});
}
try {
csvWriter.write(file, StandardCharsets.UTF_8, data);
Log.v(TAG, "csv file created");
} catch (IOException e) {
e.printStackTrace();
}
}else {
Toast.makeText(this, "Directory not exist", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "No data to export csv", Toast.LENGTH_SHORT).show();
}
The text was updated successfully, but these errors were encountered: