Colton Idle
01/30/2023, 1:00 AM@Throws(IOException::class)
fun writeStringToFile(path: Path, myMessage: String) {
FileSystem.SYSTEM.createDirectories(path)
FileSystem.SYSTEM.write(path) {
writeUtf8(myMessage)
}
}
Calling code
writeStringToFile("mydir/myMessage.json".toPath(), "hello, moto")
Keep getting java.io.IOException: failed to create directory: mydir
edit: maybe cuz im on an emu 🤔eygraber
01/30/2023, 1:06 AMColton Idle
01/30/2023, 1:08 AMColton Idle
01/30/2023, 1:09 AMeygraber
01/30/2023, 1:10 AMmydir
just a placeholder? You should be using something like https://developer.android.com/reference/android/content/Context#getFilesDir() to get a directory that you can write toColton Idle
01/30/2023, 1:16 AMColton Idle
01/30/2023, 1:19 AMwriteStringToFile("${context.filesDir}/mydir/myfile.json".toPath(), "hello, moto")
going to give that a shot 🤞Colton Idle
01/30/2023, 1:23 AM@Throws(IOException::class)
fun writeStringToFile(pathWithFileName: Path, myMessage: String) {
FileSystem.SYSTEM.createDirectories(pathWithFileName.parent!!)
FileSystem.SYSTEM.write(pathWithFileName) {
writeUtf8(myMessage)
}
}
eygraber
01/30/2023, 1:39 AMval someFile = File(parent, "foo/bar/baz").apply { parent.mkdirs() }
Aside from that, did you still have to use context.filesDir
?jw
01/30/2023, 2:23 AMBenoit Quenaudon
01/30/2023, 7:46 AMjw
01/30/2023, 7:00 PMColton Idle
01/30/2023, 7:01 PMColton Idle
01/30/2023, 7:02 PMjw
01/30/2023, 7:02 PMjw
01/30/2023, 7:06 PM