Jeff
Jeff

Reputation: 21

Create a Json File within Class

I've written a toDoList with Intellj in Java. I used simpleJson to save and load the tasks. In my repository I have a data folder where the json file is stored. However, when I package it with Intellj into a .jar, the save/load feature does not work. I am assuming this is because there's no json file attached in the packaging. Thus, is it possible to make a new Json file in the same folder where the .jar is so my program doesn't crash? In Intellij my code still runs if I delete the data file from the project view.

Upvotes: 0

Views: 76

Answers (1)

BendaThierry.com
BendaThierry.com

Reputation: 2110

Maybe using another way to store your JSON file will be better than inside a *.jar file because *jar are archives : direct serialization will not work unless you try to unpack/package the things. Bad way to go with complicated stuff for no added value.

If I were you, I will try to store these file in the user folder of your system. To get it, you can use :

System.getProperty("user.home");

Upvotes: 1

Related Questions