There is nothing wrong with the read()
, but you are calling it twice in dataFromFile()
(once in the while
condition and once inside the loop), hence the skipping of every other number. Do this instead:
int foo=0;
while ((foo=input.read()) != -1) {
System.out.print(foo + " ");