0

I have created an executable jar file. User is required to put in his/her name and save it in order to proceed. This requires creation of a file, but due to *.txt at gitignore it will not be stored in git. I would like to know the proper way to create a file, so that user will be able to put in his name and proceed. What should I add besides:

File yourFile = new File("Name.txt");
yourFile.createNewFile();
FileOutputStream oFile = new FileOutputStream(yourFile, false);

try {
    BufferedWriter reader = new BufferedWriter(new FileWriter(new File("Name.txt"), true));
    reader.write(Data);
    reader.newLine();
    reader.close();
} catch (IOException E) {
    System.out.println("Error is " + E);
}
Marek Puchalski
  • 3,286
  • 2
  • 26
  • 35
EddieJn
  • 47
  • 2

1 Answers1

0

You usually store and manage code in git. You usually don't store binaries and runtime data in git.

To my eye the code is lacking checking the existence if the file already exists. Please look here for more info: How do I check whether a file exists without exceptions?

By the way. Please don't do things like:

BufferedWriter reader (...)

It's not a reader. It's a writer.

Marek Puchalski
  • 3,286
  • 2
  • 26
  • 35