Hi all,
I need help with the save button of my java inventory program part 6. It compiles and runs but then it get the error message stating C:\data\inventory.dat"(access denied) and then general output field shows:
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
here is the snippet of the program showing my save button
JButton saveButton = new JButton("Save");
saveButton.setBounds(50, 60, 80, 30);
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event){
File dir = new File( "C:\\data\\" );
boolean isDirectoryCreated = dir.mkdir();
if(isDirectoryCreated)
System.out.println("Directory created successfully");
else
{
try
{
FileOutputStream out = new FileOutputStream( "Inventory.dat" );
try
{
ObjectOutputStream objectOut = new ObjectOutputStream(out);
Object inv = new Object();
objectOut.writeObject( inv );
}
catch (IOException e)
{
JOptionPane.showMessageDialog( null, e.getMessage() );
e.printStackTrace();
}
}
catch ( FileNotFoundException e )
{
JOptionPane.showMessageDialog( null, e.getMessage() );
e.printStackTrace();
}
}
}
});
any help would be greatly appreciated