Kotlin
val path = getExternalFilesDir(DIRECTORY_PICTURES)
Kotlin
val folderPath = getExternalFilesDir(null); // folderPath = "/storage/emulated/0/Android/data/com.example.androidkotlinapp1/files"
val filename = "1.txt"
var text = "Hello"
val data:ByteArray = text.toByteArray(Charset.forName("US-ASCII"))
val file = File(folderPath, filename); // create an object, but the file will not be created now
try {
val os:OutputStream = FileOutputStream(file);
os.write(data); // The file will be created and the data will be saved
os.close();
}
catch (e: IOException)
{
}