Sometime you are reading a file that is being used by some other process. In that case, you might not be able to read the full contents. The code below attempts again and again until it finds a predefined token at the end of the file.

Java Code:
	public void parseFile() throws Exception
	{
		ArrayList <String>myArrayList;
		while(true)
		{
		myArrayList = new ArrayList<String>();
		BufferedReader in = new BufferedReader(new FileReader(fileName));
		String fileLine;
		while (( fileLine = in.readLine()) != null) {
                myArrayList.add(fileLine);
		}
		
		if(myArrayList.get(myArrayList.size()-1).equals("ENDFILE")
		{
			in.close();
			break;
		}
		
	} //while
		fileContents = myArrayList;
	}