0

I created a jar file from a Java project. I can even run it now, but it does not save the serialization file that is stored correctly when I run the program from normal binary code outside of the JAR file.

Can’t you create new files when you have a jar file?

This is how I write the file:

FileOutputStream fileOut = new FileOutputStream("data/vocabulary.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(this);
out.close();
fileOut.close();

My JAR file looks like this:

META-INF
    MANIFEST.MF
name
    stefankoch
        …

where name/stefankoch/… is my project namespace.

I tried creating a data directory in the jar-file (root), but it did not work either. There also is a data directory within the directory the jar-file resides in, but that one is not taken either.

How can I allow jar files to create files?

aufziehvogel
  • 7,167
  • 5
  • 34
  • 56

1 Answers1

0

basically, you should not add information entered by the user into a JAR file, they belong to the user’s home directory.

This can be read with

System.getProperty("user.home")

And files within the user home directory can also be used from within a JAR file.

aufziehvogel
  • 7,167
  • 5
  • 34
  • 56