java - Binary I/O Classes (Summing all the integers in a binary data file) -
could please me through problem? i'm not binary i/o classes.
suppose binary data file named exercise 13b_1.dat has been created using writeint(int) in dataoutputstream. file contains unspecified number of integers. write program find sum of integers.
here 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 " + count + " integers."); for efficiency, can read in bunch of bytes , divide number of bytes four, since 1 integer 4 bytes.
Comments
Post a Comment