0

Suppose I have the following code in Java:

        FileInputStream fin = new FileInputStream(filename);
        DataInputStream x = new DataInputStream(fin);
        DataInputStream y = new DataInputStream(fin);
        DataInputStream z = new DataInputStream(fin);

I want to use y.skip(100) and z.skip(200) to simultaneously read data from the file at different positions. Will this work? I'm getting EOF errors at the moment...

EDIT

I did try the following code:

        FileInputStream fin1 = new FileInputStream(filename);
        FileInputStream fin2 = new FileInputStream(filename);
        FileInputStream fin3 = new FileInputStream(filename);
        DataInputStream x = new DataInputStream(fin1);
        DataInputStream y = new DataInputStream(fin2);
        DataInputStream z = new DataInputStream(fin3);

This does not produce EOF errors, but still not sure if this might return corrupted data?...

2 Answers 2

1

I seem to have found a solution. The original doesn't work because it just increments the file pointer every time, regardless of the DataInputStream used. Instead I needed to create additional FileInputStreams's. Works fine.

Sign up to request clarification or add additional context in comments.

Comments

0

In this specific case it won't produce corrupted data, but if there had been a BufferedInputStream anywhere in association with them it would have.

The real question is why on earth you would want to do this? Why can't you use the same DataInputStream?

1 Comment

I have a legacy data file containing 3d vector field data. All x values are stored first then all the y values and then all the z values, ie the data doesn't read as (x,y,z) each time. I could loop trhough the data 3 separate times, but this is onefficient on large data sets. Maybe theres another way to achieve what i want? I have no control over the data file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.