read and writing to files!!
Im trying to write to and read from a file using an object:
Write to a file:
try{
File outfile=new File("object.dat");
if(outfile.exists())
FileOutputStream ostream = new FileOutputStream(outfile);
ObjectOutputStream oostream = new ObjectOutputStream(ostream);
oostream.writeObject(aPerson);
ostream.close();
oostream.close();
}
catch(Exception e)
{
area1.setText("File Error");//displays message in text area on applet.
}
Read from File:
try{
File infile=new File("object.dat");
if(infile.exists())
FileInputStream istream = new FileInputStream(infile);
ObjectInputStream iistream = new ObjectInputStream(istream);
Person aPerson=(Person)iistream.readObject();
istream.close();
iistream.close();
}
catch(Exception e)
{
area1.setText("error");//displays message in textarea on applet.
}
The above code is incorrect:
1.What kid of file extension should i use with the file im writing to?(tried object.txt and object.dat)?
2.My applet has a save and load button with the above code used for each respectivly, the applet
will run but the buttons wont. i get this message in output window when i try to save to file:
java.security.AccessControlException: access denied (java.io.FilePermission object.dat read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkRead(SecurityManager.java:887)
at java.io.File.exists(File.java:677)
at MEMBERSHIP.PersonApplet.load1_ActionPerformed(PersonApplet.java:171)
at MEMBERSHIP.PersonApplet$ButtonListener.actionPerformed(PersonApplet.java:125)
at java.awt.Button.processActionEvent(Button.java:381)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3598)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
3.Any help is creatly appreciated.
Thank you.

