Jump to content

[java] Saving Files To A Chosen Location Within Application Code


modmouse
 Share

Recommended Posts

Main.java
public static void saveAsHandler() throws IOException, DishException
{
String fileName = StringIO.ask("file name: ");
myMenu.saveAs(fileName);
}

public static void openHandler() throws IOException, DishException, ClassNotFoundException
{
String fileName = StringIO.ask("file name: ");
myMenu.open(fileName);
}
==========================
Menu.java
public void saveAs (String aFilename) throws IOException
{
FileOutputStream outFile = new FileOutputStream (aFilename);
ObjectOutputStream itemsFile = new ObjectOutputStream (outFile);
itemsFile.writeObject(menu);
itemsFile.writeObject(codes);
itemsFile.close();
}

public void open (String aFilename) throws IOException, ClassNotFoundException
{
FileInputStream inFile = new FileInputStream (aFilename);
ObjectInputStream itemsFile = new ObjectInputStream (inFile);
menu = (Vector)itemsFile.readObject();
codes = (Vector)itemsFile.readObject();
itemsFile.close();
}[/CODE]

At the moment files are saved in the same directory as the program has been run from but when I burn it to cd of course this is not possible.

I've seen examples but I cannot work out where things like

[CODE]("Z:\\results\\results.txt"); or ("z:\\results.txt"); or ("z:/results.txt");[/CODE]

are supposed to be placed to save a file created by the java application to a pre determined location. Or even one set by the user.

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...