I've recently decided to convert my 3d model format over to a binary file instead of ASCII in the hope of a speed increase... I read some java tutorials and the simplest way of reading my format seems to be using the ObjectInputStream and a mixture of readLong() and readFloat() commands... but I can't seem to get the code to work...
Here is my test code:
void testLoadBin(String fileName, Context context){
try {
InputStream fis = context.getAssets().open(fileName);
ObjectInputStream is = new ObjectInputStream(fis);
long test;
test = is.readLong();
Log.i("World", "output" + test);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.i("World", "ERROR");
}
}
In this example I'm just trying to read the first LONG from the file, but the IOException is always thrown and I'm not sure what to do to fix this.
Any help would be useful.
Quick add: the stack trace error output:
09-18 00:16:08.559: INFO/World(3861): java.io.StreamCorruptedException
09-18 00:16:08.559: INFO/World(3861): at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2369)
09-18 00:16:08.559: INFO/World(3861): at java.io.ObjectInputStream.<init>(ObjectInputStream.java:433)
09-18 00:16:08.559: INFO/World(3861): at org.ogl.ndkvbo.Screen.testLoadBin(Screen.java:6605)
09-18 00:16:08.559: INFO/World(3861): at org.ogl.ndkvbo.camState_intload.update(camState_intload.java:24)
09-18 00:16:08.559: INFO/World(3861): at org.ogl.ndkvbo.StateMachine.update(StateMachine.java:65)
09-18 00:16:08.559: INFO/World(3861): at org.ogl.ndkvbo.camera.update(camera.java:46)
09-18 00:16:08.559: INFO/World(3861): at org.ogl.ndkvbo.GameThread.run(GameThread.java:50)
You must use ObjectOutputStream() if you want to use ObjectInputStream(). However nothing prohibits you as ObjectInputStream and ObjectOutputStream extend from DataOutputStream and DataInputStream.
So it will be helpful if you could also post the code snippet where you are writing to file. Also check if fis in the line InputStream fis = context.getAssets().open(fileName);
is correct and actually points to the file that you intend to read from.