Reading files
I can open the file and read it but i would like to be able to put it into a string or something so i can use it again in other objects.
I need to create an object (which i have done) which displays the contents of the file and i also need to create an object which counts the words (which i have done also).
I need to be able to use a variable which holds the entire string of what's in the file so i can reuse it but am unsure how I would do it.
Here is the code that i have which reads the file in and displays it but is there a way i can read the file once and reuse what is read by other objects?
String textline, getFile;
//Constructor
public Document(String fileName)
{
getFile = fileName;
}
//Method for reading in the file text
public void readFile() throws IOException
{
//Open the requested file for reading
FileReader file = new FileReader(getFile);
BufferedReader MyFile = new BufferedReader(file);
while((textline = MyFile.readLine()) !=null)
{
System.out.println(textline);
}
}

