I need to read in a file that's been saved in Java Android Studio with this code
fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(json);
os.close();
fos.close();
It turns out that Java uses internally UTF-16 for encoding the characters. I now need to read this files in Flutter SDK (with the Dart language)
file.readAsString(encoding: Latin1).then((str) => {
print(str)
}).catchError( (e) => {
print(e)
});
However, the Latin1 encoding doesn't work perfectly. So I want to read it in using UTF-16 but it seems that Dart does simply not have this functionality, or at least not that I can find.
Utf8Codec
does exist but there's not Utf16Codec
nor Encoding.getByName("UTF-16")
. Utf8 is by the way giving exceptions so this is also no option.
So how can I still read in files in Dart which have been saved in Android Studio Java using UTF-16?