0

I have desktop application. I do jar-file, but I have file into this jar what is needed to be change. I use TrueZip <> I tried:

OutputStream out = new FileOutputStream("myjar.jar"+"/com/mycompany/confProperties.properties");
try{
    properties.store(out, "Changed by User");}
finally{
    out.close();
}
TFile.umount();

It work with Eclipse, but when I execute my jar from command line I have exception:

java.io.FileNotFoundException: myjar.jar/com/mycompany/confProperties.properties
at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:147)
at de.schlichtherle.truezip.file.TFileOutputStream.<init>(TFileOutputStream.java:83)

If I use only "/com/mycompany/confProperties.properties" instead of "myjar.jar"+"/com/mycompany/confProperties.properties", I have

java.io.FileNotFoundException: \com\fujitsu\gdcru\accesschecker\client\confProperties.properties
at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:147)
at de.schlichtherle.truezip.file.TFileOutputStream.<init>(TFileOutputStream.java:83)

Can I change this file? And how?

Holger
  • 285,553
  • 42
  • 434
  • 765
RuF
  • 548
  • 1
  • 11
  • 31
  • Did you mean `FileOutputStream` or `TFileOutputStream`? I suspect the real problem is that `myjar.jar` is not where your code expects it to be. – Ian Roberts Jan 17 '14 at 11:11
  • 1
    But as an aside, it's generally a really bad idea for a program to make changes to its own JAR while it is running - if you want to store user settings you should use the `java.util.prefs` Preferences API, or if you must use a `.properties` file then create it in a known location under the user's home directory or some other directory where you know you'll have write permission. For example, imagine if your program is installed under `Program Files` on Windows and the user running it doesn't have admin rights... – Ian Roberts Jan 17 '14 at 11:14
  • The code doesn't match the exception or vice versa. Please use A TFileOutputStream and make sure that the JAR for the module TrueZip Driver ZIP is on the class path. Also, please note you can't reliably modify JARs which are placed on the class path of the application which tries to modify it, that would be a circular dependency. – Christian Schlichtherle Jan 18 '14 at 08:54

0 Answers0