-2

I'm creating an application that helps with tracking the estimated earnings that someone can make based on the amount of questions that they've done. What I'm trying to do is store the amount of questions that they've already done and the earnings total.

I've tried to do this with a text file before, but when I've tried to make the entire application into a jar file, the text file doesn't work. I was hoping that the jar file would be able to read from the text file, but it doesn't and the data doesn't save. Is there any better way to do this so the application can save data on any user's computer?

Elijah
  • 1
  • 2
    User preferences, or a plain text file, JSON, XML, CSV, a database, ... all depending on specific needs. And yes, a plain text files works with a jar file, but you can't (easily) include the file into the jar if you plan to write to it. So keep it out of the jar file. – Hovercraft Full Of Eels Aug 19 '23 at 18:37
  • Thank you for the quick response. Since the text file method is still viable, what is the best way to get it to save without the file needing to be within the working directory? I've tried this before with another project, but I've never figured it out. – Elijah Aug 19 '23 at 18:43
  • You can put it anywhere you like, anywhere you are allowed to place it that is per the OS. But first you need to state explicitly where you want the file to be. You haven't done this. Please tell the details of your problem, my friend. We are terrible at reading minds. – Hovercraft Full Of Eels Aug 19 '23 at 18:50
  • You're right, I should be more specific. What I actually want to know how to do is read from a text file that's outside of the working directory (like if the text file was on the Desktop), but every relative path that I'm using doesn't work. I've been trying to use ".." to file in the blanks, but that never works. Is there any other way to do this? – Elijah Aug 19 '23 at 22:00
  • @Elijah, it might be a better idea to use the full path for files outside of the working directory. And, review the _[FileReader](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/io/FileReader.html)_ and _[FileWriter](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/io/FileWriter.html)_ classes, to learn more about reading and writing files. – Reilas Aug 19 '23 at 22:11
  • I've figured out what I've been doing wrong. Because Windows after 10 and 11 has OneDrive preinstalled, it was messing up the directory. So I decided to create an if statement that considers a directory for Desktop that has OneDrive and another one that doesn't. Thank you for the help! – Elijah Aug 19 '23 at 22:29

0 Answers0