main
class
PHP Code:
import search.search_song;
/**
* Created with xgiovio.macbookair.
* User: xgiovio
* Date: 23/09/13
* Time: 14:57
*/
public class test {
public static void main (String [] input_data) throws Exception {
search_song.name_print_song("library.dat","Francesco");
}
}
PHP Code:
package search;
import java.io.File;
import java.util.Scanner;
/**
* Created with xgiovio.macbookair.
* User: xgiovio
* Date: 15/10/13
* Time: 14:31
*/
public class search_song {
public static void name_print_song (String library, String name_to_search) throws Exception{
String temp;
boolean print = false;
Scanner lettore = new Scanner(new File(library));
for( ;lettore.hasNextLine(); ) {
temp = lettore.nextLine();
if (temp.equals(name_to_search)){
System.out.println("Artist: " + name_to_search + " - Song: " + lettore.nextLine());
print = true;
}else{
lettore.nextLine();
}
}
if (!print) {
System.out.println("No song found for " + name_to_search );
}
}
}