File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Remember last file opened Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Remember last file opened" Watch "Remember last file opened" New topic

Remember last file opened

mark geroso

Joined: Oct 12, 2006
Posts: 24
My Prof assigned this project... A frame, text area in the center, panel in the south containing a text field. Any text file opened would show its contents in the text area and the path and filename in the text field.

I did it, but I can't figure out how to make it remember which file was last opened.
Say, you run the program, open a text file, save and close the file, then close the program. If you run the program again, it will open the last file accessed automatically.
I thought about assigning the path to a string variable, but won't all variables be cleared when you close the program?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Yes. You'd have to save the path into a little preferences file for your program, loaded when your program starts up.

[Jess in Action][AskingGoodQuestions]
mark geroso

Joined: Oct 12, 2006
Posts: 24
Thanks. I was thinking of that, I was just hoping there would be a more elegant solution.
I'm gonna go do that now.
I agree. Here's the link:
subject: Remember last file opened
jQuery in Action, 3rd edition