First page Back Continue Last page Overview Graphics
Reading a file of integers revisited (The right way)
public static int[] readNumbersFromFile
- ( String fileName, int n) throws IOException{
- int[] arr = new int[n];
- DataInputStream dataIn = new DataInputStream(
- new BufferedInputStream(
- new FileInputStream(fileName)));
- int currByte;
- int currInt;
- for(int i = 1; i < n; i++){
- arr[i] = dataIn.readInt();
- }
- fileIn.close();
- }