/* * Reading in a text file ie possible names for a team. * NB The text file only has one word per line. */ package sixasidebeachtext; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JOptionPane; public class SixASideBeachText { public static void main(String[] args) { String [] teamName = new String[20]; int size = 0; // Populate the teamName array. // Reads in a text file, one name per line, no delimiter try { Scanner scFile = new Scanner(new File("SixASideBeachText.txt")); while (scFile.hasNext()) { String line = scFile.nextLine(); // Only one word per line teamName[size] = line; size++; } } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, "Error! File not found"); System.exit(0); } } } ====================================================== This is what the text file looks . . . Mercury Venus Mars Jupiter Saturn Uranus Neptune Astroid Comet Rhea Callisto Io Europa Ceres Luna Titan Hyperion Janus Oberon Ariel