我正在寻找按姓氏字母顺序从文件中读取的联系人排序到控制台?我该怎么做呢?联系人已经以姓氏开头写入文件,当用户想要在控制台中查看联系人时,我只想按字母顺序将它们读回应用程序。
// Read from file, print to console. by XXXXX
// ----------------------------------------------------------
int counter = 0;
String line = null;
// Location of file to read
File file = new File("contactlist.csv");
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
line = scanner.nextLine();
System.out.println(line);
counter++;
}
scanner.close();
} catch (FileNotFoundException e) {
}
System.out.println("\n" + counter + " contacts in records.");
}
break;
// ----------------------------------------------------------
// End read file to console. by XXXX