我正在尝试让文件扫描程序在下一行为空白时停止扫描。
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
请注意,包含所有曲目标题的行不会自动换行。该行将被读入数组列表。请注意,在曲目标题的下方,有一个价格,然后是一个空白行。我要这个 空白行是扫描仪的停止点,但我无法获得语法。
谢谢!