Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int[][] readMatrixFromFile() throws FileNotFoundException {
- Scanner input = new Scanner (new File("D:\\Eclipse\\matrix.txt"));
- // pre-read in the number of rows/columns
- int rows = 0;
- int columns = 0;
- while(input.hasNextLine())
- {
- ++rows;
- Scanner colReader = new Scanner(input.nextLine());
- while(colReader.hasNextInt())
- {
- ++columns;
- }
- }
- int[][] a = new int[rows][columns];
- input.close();
- // read in the data
- input = new Scanner(new File("src/array.txt"));
- for(int i = 0; i < rows; ++i)
- {
- for(int j = 0; j < columns; ++j)
- {
- if(input.hasNextInt())
- {
- a[i][j] = input.nextInt();
- }
- }
- }
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement