After my poor showing yesterday I was ready to quit, but I decided this morning I would rather feel dumb than feel like a quitter, so here I am.
I coded this last night thinking if it worked great, if not then I would just drop it. Well it worked ... kind of.
I want to write my JList to a file on the harddrive, so I created a button that does this, and the file is created just fine, in the same directory as all my classes and java files. Not where I want it. I tried changing the path to a c:\data\ directory, but my method will not put the file there, even if I manually create the directory it will not do it.
private void btnSaveActionPerformed(ActionEvent evt)
{
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
try
{
// create a new file output stream
// connected to "myfile.txt"
out = new FileOutputStream("inventory.dat");
// connect print stream to the output stream
p = new PrintStream(out);
p.println (listModel);
p.close();
}
catch (Exception e)
{
System.err.println ("Error writing to file");
}
}// end SAVE
Why can I not change location of my output? And if I can, can I make JAVA create the directory for me if it is not already there?