I have little experience using delimiters and i need to read a text file that stores several objects whose data is stored in single lines separate by commas (\",\"). The sep
I think you want to call .next()
which returns a String instead of .nextLine()
. Your .nextLine()
call is moving past the current line.
Scanner read = new Scanner (new File("datafile.txt"));
read.useDelimiter(",");
String title, category, runningTime, year, price;
while(read.hasNext())
{
title = read.next();
category = read.next();
runningTime = read.next();
year = read.next();
price = read.next();
System.out.println(title + " " + category + " " + runningTime + " " + year + " " + price + "\n"); //just for debugging
}
read.close();