I am trying to write a program to display a files contents. It's fairly simple, but I can't find anything on how to open a file multiple times and read from the beginning each time. I will try and post the whole class, it isn't very long so maybe it will fit.


public class FileDisplay
{
//Instance Variable which references the Text file
private String fileName;
//File class which opens the Text File
File inFile = new File("TestFile.txt");
//Scanner class which reads the Text file
Scanner inputFile = new Scanner(inFile);

/**
* FileDisplay constructor which creates FileDisplay objects
* fName, which stores the String representing the Text file
* @param fName
* IOException thrown
* @throws IOException
*/
public FileDisplay(String fName) throws IOException
{
fileName = fName;
}

/**
*
*/
public void displayHead()
{
for(int num = 0; num <= 4; num++)
{
String str = inputFile.nextLine();
System.out.println(str);
}
inputFile.close();
}


/**
*
*/
public void displayContents() throws IOException
{
openFile();
if(inputFile.hasNextLine())
{
for(int num = 0; num <= 4; num++)
{
String str = inputFile.nextLine();
System.out.println(str);
}
}
else
{
inputFile.close();
}
}

/**
*
*/
public void displayWithLineNumbers() throws IOException
{
openFile();
int lineNum = 1;
while(inputFile.hasNextLine())
{
String str = inputFile.nextLine();
System.out.println();
lineNum++;
}
inputFile.close();
}

private void openFile() throws IOException
{
//File class which opens the Text File
File inFile = new File("TestFile.txt");
//Scanner class which reads the Text file
Scanner inputFile = new Scanner(inFile);
}

}