我正在尝试从 .rtf 文件打印,但似乎我的 if 语句已损坏。似乎拆分不起作用,因为如果我设置了打印状态输出只是作为第一行打印出来,它告诉用户他们正在搜索哪首歌,然后是未格式化的歌词。除此之外,代码只是循环通过 while 循环。似乎它在点击时没有找到歌曲if(line.contains(song)){
。现在,我只是硬编码文件的位置,但当我让它工作时,我会让该方法使用用户输入。
任何帮助,将不胜感激。
public static void main(String[] args){
lyricsSearch("/Users/adam/Documents/Final/BlackDahliaMurder/", "miasma.rtf");
}
public static void lyricsSearch(String artist, String song){
try {
String stringSearch = song;
// Opens the album file as a buffered reader
BufferedReader bf = new
BufferedReader(new FileReader("/Users/adam/Documents/Final/BlackDahliaMurder/miasma.rtf"));
// Let the user know what we are searching for
System.out.println("Searching for " + song + "...");
// Loop through each line, parsing.
String line;
while (( line = bf.readLine()) != null){
System.out.println(line);
if (line.contains(song)){
String[] songInfo = line.split("\\|");
System.out.println(Arrays.toString(songInfo));
}
}
bf.close();
}
catch (IOException e) {
System.out.println("IO Error Occurred: " + e.toString());
}
}