# korge

Michael Sigl

02/11/2021, 7:03 AM
Hi, I know how to read from a VfsFile, but what's about writing? I want to write to a xml file. Basically I want to specify the file-path and the data as parameters into a function. If the file already exists, it should be opened and written to in in xml style. If it doesn't exist, it should be created first and then opened and then written data to it. How to do that?

Deactivated User

02/11/2021, 8:09 AM
Copy code
val file = yourVfsFile
if (!file.exists()) file.writeString("")
Copy code
return file.readString()
Korio does't provide automatic serialization for any type, but only json for primitive types like maps, lists, numbers, bools and strings. For converting any object into an XML you can use jackson if you are using JVM only, or kotlinx-serialization for multiplatform projects. Those are separate libraries to korlibs, but you can find help in other channels or the internet about how to use them. For the korio part: you should end reading and writing plain strings from/to files and do the de/serialization part with those strings