I have a program in C# .net which writes 1 integer and 3 strings to a file, using BinaryWriter.Write()
.
Now I am programming in Java (for Android, and I'm new in Java), and I have to access the data which were previously written to a file using C#.
I tried using DataInputStream.readInt()
and DataInputStream.readUTF()
, but I can't get proper results. I usually get a UTFDataFormatException
:
java.io.UTFDataFormatException: malformed input around byte 21
or the String
and int
I get is wrong...
FileInputStream fs = new FileInputStream(strFilePath);
DataInputStream ds = new DataInputStream(fs);
int i;
String str1,str2,str3;
i=ds.readInt();
str1=ds.readUTF();
str2=ds.readUTF();
str3=ds.readUTF();
ds.close();
What is the proper way of doing this?