As of right now, I have a text file called lol.txt and my code prints out a line in the file with a "|" between each word. For example, the first line prints "hello|howdy|hola" and I want to split this at the pipe so I can randomly pick a greeting from that line. I am confused on why my delimiter is not working and how I would go about converting it to an array so I can take the index of the first line so greeting[0] would print "hello".
Scanner sc = new Scanner(System.in);
// open file and prompt for file name
System.out.print("Enter a file name: ");
String fileName = sc.nextLine();
File infile = new File(fileName);
Scanner readIt = new Scanner(infile);
//prints <greeting> of text file. Ex. hello|howdy|etc...
String greeting = readIt.nextLine();
greeting.split("|");
System.out.println(greeting);