I have a two-dimensional array of objects that I store in a file in the Assets folder of an Android Studio project. The file is serialized and named "maindata.conv"
Reading the file in Java is a breeze:
static public Object[][] mainTable = null; ObjectInputStream instream = new ObjectInputStream(getAssets().open("maindata.Conv")); mainTable = (Object[][]) instream.readObject(); But when I translate the code to Kotlin, the translated code does not work:
val instream = ObjectInputStream(assets.open("maindata.Conv")) MainActivity.mainTable = instream.readObject() as Array<Array<Any?>?> The word "open" is flagged in red as "unresolved". Nothing I try to import works. How do I read a raw file in Kotlin from the Assets folder? Please help.
assets. `open`instead ofassets.openasopenis a Kotlin keyword.assetsis just a shorthand forgetAssets()which is a method on aContext- so if you call that inside anActivityit will just work. The Java code is the same so you must be calling it from a different place in the Kotlin version?