I'am trying to read a file which is .csv file into an array with the first index of each line in the file.
What I want to achieve is only the first word of each line, not like the image below:
Bonaqua
California
Gallardo
City
Skyline

Below is my read file class:
import java.io.File;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class readfile {
private Scanner s;
public void openFile() {
try {
s = new Scanner(new File(readpath.a));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "File not found!");
}
}
public void readFile() {
String read = "";
while (s.hasNextLine()) {
read += s.nextLine() + "\n";
}
String menu[] = read.split("\n");
Object[] selectionValues = menu;
String initialSelection = "";
Object selection = JOptionPane.showInputDialog(null,
"Please select the Topic.", "Reseach Forum Menu",
JOptionPane.QUESTION_MESSAGE, null, selectionValues,
initialSelection);
JOptionPane.showMessageDialog(null, "You have choosen "
+ selection + ".", "Reseach Forum Menu",
JOptionPane.INFORMATION_MESSAGE);
if (selection == null) {
JOptionPane.showMessageDialog(null, "Exiting program...",
"Research Forum Menu", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
public void closeFile() {
s.close();
}
}