Here is my code to write the arraylist to .dat file, And im not sure if its working but it writes to the file and i can see all the random characters so it is writing something but i keep getting io errors when i try to use the method.
/** Writes all requests to the specified file
* @param fname name of file storing requests
*/
public void writeRequestsToFile(String fname)
{
try
{
FileOutputStream fileOut = new FileOutputStream(fname);
ObjectOutputStream oos = new ObjectOutputStream (fileOut);
oos.writeObject (allRequests);
oos.close();
} catch (FileNotFoundException e) {
System.out.println("File Not Found");
} catch (IOException e) {
System.out.println("IO Exception");
}
}
/** reads all requests from the specified file and stores
* @param fname name of file storing requests
*/
public void readRequestsFromFile(String fname)
{
try
{
FileInputStream fileIn = new FileInputStream(fname);
ObjectInputStream ois = new ObjectInputStream (fileIn);
Object obj = ois.readObject();
allRequests = (ArrayList) ois.readObject();
ois.close();
} catch (FileNotFoundException e) {
System.out.println("File Not Found");
} catch (IOException e) {
System.out.println("IO Exception");
} catch (ClassNotFoundException e) {
System.out.println("Class Not Found");
}
}
The Object i am Writing is an ArrayList called allRequests