It is necessary to read data from a text file into a two-dimensional array. Data is stored in a .txt file in this form:
1 2 4
2 3.4 5
22 0 0

How to do it?

Scanner scanner = null; try { scanner = new Scanner(new File("matrix.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } String line = scanner.nextLine(); String[] string = line.split(" "); 

Everything, has adjusted this business. It's just late and the brain does not work already)

The question is only one - how to read as long as there is something to read?

    2 answers 2

    while (scanner.hasNext ()) {

    • Yes, thank you, just now coped with this ... - Stas0n

    I did another: private void OpenTextFile () {

      Scanner scanner = null; try { scanner = new Scanner(new File("c:\\2x3x4_48.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } String line = new String(); String[] str=new String[5]; //= line.split(" "); System.out.println(str.length); for (int i=0; i<5; i++) { line = scanner.nextLine(); //System.out.println(qator); str[i]=line; System.out.println(str[i]); } }