public static int[] readVectorFromFile(String file) throws Exception {
        Scanner sc;
        FileInputStream fis = null;
        int n;
        int[] v;
        try {
            fis = new FileInputStream(file);
            sc = new Scanner(fis);
            if (!sc.hasNextInt()) {
                throw new Exception("Could not read the number of elements the vector has.");
            }
            n = sc.nextInt();
            v = new int[n];
            for (int i = 0; i < n; i++) {
                if (!sc.hasNextInt()) {
                    throw new Exception("Number of declared elements does not match with the one found in file.");
                }
                v[i] = sc.nextInt();
            }
            fis.close();
        } catch (Exception ex) {
            if (fis != null) {
                try {
                    fis.close();
                } catch (Exception e) {
                }
            }
            throw ex;
        }
        return v;
    }