您可以使用正则表达式来检测更长的空格,例如:
String text = "ID SALARY RANKn" + "065 12000 1n" + "023 15000 2n" + "035 25000 3n" + "076 40000 4n";Scanner scanner = new Scanner(text);//reading the first line, always have header//I supposeString nextLine = scanner.nextLine();//regex to break on any ammount of spacesString regex = "(\s)+";String[] header = nextLine.split(regex);//this is printing all columns, you can //access each column from row using the array//indexes, example header[0], header[1], header[2]...System.out.println(Arrays.toString(header));//reading the rowswhile (scanner.hasNext()) { String[] row = scanner.nextLine().split(regex); //this is printing all columns, you can //access each column from row using the array //indexes, example row[0], row[1], row[2]... System.out.println(Arrays.toString(row)); System.out.println(row[0]);//first column (ID)}


