Heyo! I'm looking to write a simple app log file u...
# squarelibraries
d
Heyo! I'm looking to write a simple app log file using Okio on Kotlin Multiplatform for iOS/Android. This will literally just be a text file and I'm just writing strings to it. I added Okio to my KMP project and in my commonMain I wrote the example provided:
Copy code
val path = "applog.txt".toPath()       
        FileSystem.SYSTEM.appendingSink(path).buffer().use { sink ->
            sink.writeUtf8(message)
        }
I get an error on both iOS and Android
Copy code
Caused by: java.io.FileNotFoundException: applog.txt: open failed: EROFS (Read-only file system)
	at libcore.io.IoBridge.open(IoBridge.java:492)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
	at okio.Okio__JvmOkioKt.sink(JvmOkio.kt:173)
Looking around it looks like Okio w/ KMP works in common now but I'm not seeing many examples?
1
j
Your path is relative, and the working directory is probably something unusable like
/
.
Where are you expecting the file to go?
d
Just in the app container, so for android /data/data/com.appname/
j
That is the path you should specify then, although ideally deriving it from the getDataDir API or whatever it's called
d
getDataDir from okio or just using expect/actuals with iOS/Android? Not seeing anything in okio api so likely just gonna do the expect/actuals
j
I don't know what your code looks like, but you could also just inject the base Path into your common code as a parameter and then build upon that with relative paths.
d
Yeah sounds good, thanks!