Save csv file to Downloads directory #73
Closed
javaherisaber
started this conversation in
General
Replies: 1 comment
-
Seems like saving file in Android 11+ is no different than older versions (only reading and sharing content have changed) val data = mutableListOf<Array<String>>() // add your data here
val root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
val file = File(root, "fileName.csv")
if (file.exists()) {
file.delete()
}
val csvWriter = CsvWriter.builder().build(file.writer())
try {
data.forEach { row ->
csvWriter.writeRow(row.toList())
}
} catch (ex: IOException) {
ex.printStackTrace()
} finally {
csvWriter.close()
} Make sure to ask for runtime permission: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:requestLegacyExternalStorage="true" >
</application> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How can I save the csv file to the Downloads directory in Android 11+?
Beta Was this translation helpful? Give feedback.
All reactions