简体   繁体   中英

Why Cant I Read/Write to Text File In Android Studio Kotlin

I am trying to simply write a line of text to a file in Android Studio but for some reason whenever I run the line of code the application crashes.

fun editNote2 (buttonView: View) {

    File("/app/sampledata/NoteText.txt").writeText("Hello world!")

}

I am a beginner so a simple answer would be nice, if there even is such a thing.

You should add Read&Write Permissions in AndroidManifest file. Please check below:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM