1

Looking for some best practice advice, I am writing a java app and have a txt file which the app will read at start up and generate a series of objects, the user will have the option to add additional objects and I want to update the initial txt file to hold this information also (the txt file will be dynamic).

What is the best practice approach to this? One option I'm exploring is having an initial file within the JAR and if the user updates, create a second file in user.home, the app searches user.home initially and if nothing defaults to JAR resource txt file, what do you think? Will this work cross platform? is there any issues with this approach?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
GordonW
  • 1,120
  • 2
  • 16
  • 36
  • 1
    I think your first option. So much so, that I have voted to close as a duplicate of a question for which that is the accepted answer. – Andrew Thompson Jan 08 '14 at 09:08
  • It seems reasonable and should work cross platform. – assylias Jan 08 '14 at 09:09
  • My question really is what is best practice, I got my proposed solution from this question but there were some conflicts, in industry, how would this be acheived? storing temp file to user.home? or ... – GordonW Jan 08 '14 at 11:35

1 Answers1

0

Not to break portability you have to care for system dependent parameters like "line.separator", "file.separator" while accessing a file in the file system. You have get system specific representation of these parameters from the system at runtime as follows:

String lineSeparator = System.getProperty("line.separator");
String fileSeparator = System.getProperty("file.separator");
String userHome = System.getProperty("user.home");

String filePath =userHome+fileSeparator+"fileName.txt";
Serdar
  • 383
  • 1
  • 9