I'm currently writing a program where the program reads in words from a .txt file and stores the data into an array. The user then has the ability to enter in entries into array and the program then writes everything to the txt file where it can be read again. As well as do various other fuctions...Yet, I got every other part of it working but then i came up with the idea for the program to display the total number of elements active within the array. I did this so if the user prints out all the data to the screen or someone were to look into the file they'd know how many entries there are.
A sample file would look like this(3 is the total number within the current array/number of entries:
3
Jane Hook 1 02 11 1998
Sam golden 2 11 12 1989
Jim carl 3 12 30 1991
So I created Get/Set methods to handle the 3 when it came up with errors but now I cannot get the class that it reads in from to skip the first line of the file and just read the entries effectivly.
//This is main:Assume all the proper declaritions and imports have been done.
Scanner sf = null;
new
try
{
sf = new Scanner(new FileReader(filename));
}
catch (Exception e)
{
System.out.printf("ERROR no file found");
}
class.Setnumelements(sf);
class.Store(sf,linenumber);
public void Store(Scanner s,int linenumber)
{
do
{
m_Patient[count].Read(s);
count++;
m_NumElements++;
}while(linenumber > count);
}
}
Code blocks are created by indenting at least 4 spaces
... and can span multiple lines
So does anyone know anything that I scanner can do to SKIP over the first line of the txt file which would allow this code to work? Otherwise it'll get a inputmismatch because the first thing m_Patient reads in is a string.