Binary I/O Classes (Summing all the integers in a binary data file)?

Here is a simple solution. FileInputStream fis = new FileInputStream("13b_1. Dat"); DataInputStream dis = new DataInputStream(fis); int count = 0; try { while (true) { dis.readInt(); count++; } } catch (EOFException e) {} System.out.

Println("There are " + count + " integers. "); For efficiency, you can read in a bunch of bytes and divide the number of bytes by four, since one integer is four bytes.

Of course, using exceptions for control flow isn't terribly good style. If only there was some way to figure out how many ints are in that file. – Dmitri Dec 3 '10 at 2:47 @Dmitri: If writeInt writes a constant number of bytes for every argument, you could divide the file length by that number to get the number of integers in the file.

– Thomas Dec 3 '10 at 18:18 @Thomas: I was using gentle sarcasm to guide the author of the question towards the path to a solution :) – Dmitri Dec 3 '10 at 23:13.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions