public static void main(String[] args) throws IOException, ClassNotFoundException { // Variables ObjectInputStream fileIn; ObjectOutputStream fileOut; String fileName = "Assigment2File.dat"; // File Name to Read Message tempMessage; int noMessages = 0; int menuChoice = 0; // Creates and Instance of PriorityQueue PriorityQueue pQueue = new PriorityQueue(); while (menuChoice != 7) { menu(); System.out.println("Please choose your desired task"); menuChoice = Text.ReadInt(in); if (menuChoice == 1) { try { //Open the desired file fileIn = new ObjectInputStream(new FileInputStream(fileName)); //read number of objects in file noMessages = fileIn.readInt(); tempMessage = null; for (int i = 0; i < noMessages; i++) { tempMessage = (Message) fileIn.readObject(); System.out.println(tempMessage.getMessage()); i = i + 1; } fileIn.close(); } catch (Exception e) { System.out.println("File input error"); } } System.out.println(pQueue.count()); clearscreen(); }
From all the lecture notes i have read, this should allow me to read from the file, and print the contents to screen, but it dosen't.
Any ideas?