• Post Reply Bookmark Topic Watch Topic
  • New Topic

file path retention  RSS feed

 
Philip Mat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm creating a monthly planner program in java swing. I'm planning to use a file to serialize the objects. Right now, I've hard coded the file path in the program.
What I want to do later is to ask the user to provide a file path and use that file path for serialization.
But I don't know how to retain or embed that file path in the program. When the user exits the program, the file path will be lost and next time when the program starts, it doesn't know where to find the old serialized file.
Can you help?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could write it to a configuration file. The program would start up, read the .cfg file and see if the path was defined or not.
 
Philip Mat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But still I need to hard code the file path for the configuration file in the program, right?
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can just take the user's input and write it to the configuration file, like Fred said. If they want to change the path allow the option to overwrite the existing path in the .cfg file.


Hunter
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Philip Mat wrote:But still I need to hard code the file path for the configuration file in the program, right?
yes. Your program will need to know where the .cfg file is. You can hard-code it, you can have your install set a system parameter, you can ask the user each and every time...

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hunter McMillen wrote: No, you can just take the user's input and write it to the configuration file, like Fred said. If they want to change the path allow the option to overwrite the existing path in the .cfg file.

Hunter, read the question a little more closely. The OP is now asking if the CONFIG file needs to be hard-coded - not the file name for the serialization.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct, my mistake.

Hunter
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Base it on System.getProperty("user.home"). Or use java.util.prefs.Preferences.
 
Philip Mat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your replies.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!