我试图让文件扫描仪在下一行为空白时停止扫描。
public static void createAudioTypes(File list, Scanner mediaReader, String mediaType) {
if (mediaType.equalsIgnoreCase("CD") || mediaType.equalsIgnoreCase("CASSETTE")) {
String title = mediaReader.next();
String artist = mediaReader.next();
int year = 0;
if (mediaReader.hasNextInt()) {
year = mediaReader.nextInt();
}
String lbl = mediaReader.next();
ArrayList<String> songs = new ArrayList<String>();
System.out.println(title);
System.out.println(artist);
System.out.println(year);
System.out.println(lbl);
mediaReader.useDelimiter(",");
while(mediaReader.nextLine().equalsIgnoreCase(mediaType)) {
songs.add(mediaReader.next());
}
System.out.println(songs);
}
}
我正在阅读的部分文本文件:
CD
Immersion
Pendulum
2011
Atlantic
Genesis, Salt in the Wounds, Watercolour, Set Me on Fire, Crush, Under the Waves, Immunize (feat. Liam Howlett), The Island - pt. 1 - Dawn, The Island - pt. 2 - Dusk, Comprachicos, The Vulture, Witchcraft, Self vs Self (feat. In Flames), The Fountain (feat Steven Wilson), Encoder
16.99
CD
Demon Days
Gorillaz
请注意,所有曲目标题的行没有自动换行。这一行将被读入一个数组列表。请注意,就在曲目标题行的下方,有一个价格,然后是一个空白行。我希望这个空白行成为扫描仪的停止点,但我无法获得语法。
谢谢!