public static <N extends Number> SparseMatrix<N> fromFile(File file, Vectors.Factory<N> using) throws IOException, VectorFormatException { final BufferedReader in = new BufferedReader(new FileReader(file)); String s; final int m = Integer.parseInt(in.readLine()); final int n = Integer.parseInt(in.readLine()); @SuppressWarnings("unchecked") final Vector<N>[] vectors = (Vector<N>[]) new Vector<?>[m]; int idx = 0; while ((s = in.readLine()) != null) { if (idx >= m) { throw new VectorFormatException("Too many lines"); } vectors[idx++] = using.fromString(s, n); } return new SparseMatrix<N>(n, vectors, using); }