I have a data in a text file which is in format:
AB-9, Gregson, Brian, R T, Mr
I want to divide the up into and store the first one, AB-9
, in a local variable, I have done all of that but the problem currently is that when I print the value of id, it prints with ,
. How can I get rid of the extra comma?
Another issue is that the first line in the data is not being read.
public void readData()
{
File theNewData = new File("new_data.txt");
Scanner inputFrom = new Scanner(theNewData);
while(inputFrom.hasNextLine())
{
String lineOftext = inputFrom.nextLine().trim();
Scanner scanner = new Scanner(lineOftext).useDelimiter(",[ ]*");
String id = inputFrom.next();
System.out.println(id);
}
inputFrom.close();
}