Aldin-SXR

readNumbers

Feb 27th, 2020
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. /* Read the integer list from a file in the given path */
  2. public static int[] readNumbers(String path) throws FileNotFoundException {
  3.     int[] numbers = new int[100];
  4.     Scanner scanner = new Scanner(new File(path));
  5.     int i = 0; // counter
  6.     while (scanner.hasNextLine()) {
  7.         numbers[i] = Integer.parseInt(scanner.nextLine());
  8.         i++;
  9.     }
  10.     scanner.close();
  11.     return numbers;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment