0

I want to save which recipe collection was last loaded into the application. The path of the most recently loaded serialized recipe collection object is stored in a .ser file inside the jar file of the application. And of course I can read this .ser file no Problem by using this getRessourceAsStream() method. But writing doesn't seem to be possible. So how do I best save this .ser file storing the URI to the last loaded serialized object, so that writing is also possible?

EDIT: I don't want to save INSIDE a .jar because Class.getResourceAsStream(String) as used here only returns an INPUTStream, but I need an OUTputStream to write to a file, which doesn't seem to be possible for .jar resources. So I want to know how I can accomplish what I need, saving an object in a .ser file which can be written to and read by the .jar, with the file stored outside of the .jar.

Community
  • 1
  • 1
Dwagner
  • 237
  • 4
  • 11
  • 1
    Are you looking to [store files inside a jar file](http://stackoverflow.com/questions/4056682/how-can-my-java-program-store-files-inside-of-its-jar-file)? – Ryan Jackman Jun 30 '16 at 20:57
  • I look for a way to "save URI of serialized Object between sessions", I currently have a .ser file inside the .jar of my program that saves the URI of a serialized object which is the most recent selected via a Filechooser in the application. My goal is when the user opens the application again that the last selected recipe collection is loaded. But you can't write to a Ressource(which is needed when another collection is loaded) because getRessourceAsStream() is actually an inputstream, so where and how should I save this .ser file containing the URI of the last loaded recipe collection? – Dwagner Jun 30 '16 at 21:07
  • Don't just completely repeat yourself. Answer the question, and take the hint. This is a duplicate. Then read the duplicate. You can't do this. – user207421 Jul 01 '16 at 01:05
  • @EJP I don't get it, I repeated myself to explain how I actually DON'T want to save inside a .jar, because I already tried and in some thread I read that you shouldn't store resources that are written to inside a .jar, because that could cause problems and as I explained many times before if you access resources by using Class.getResourceAsStream(String) it only returns an inputstream, am I stating things so unclear? – Dwagner Jul 01 '16 at 10:04
  • I am unable to make any sense out of 'a .ser file which can be written to and read from the .JAR' if it doesn't mean exactly what you are now disclaiming. – user207421 Jul 01 '16 at 10:06
  • 'a .ser file which can be written to and read from the .JAR' don't you know what a .ser file is, or what? I don't get what you are not getting :D. I want to know how/where to save this file and how to best access it, so how to get the path and so on. For example you have a directory and there you have the .jar and the .ser, how could you then access that file(the .ser from the .jar), if everything is set up as I described? I hope it got a bit clearer now :). – Dwagner Jul 01 '16 at 10:13
  • You are trying to write a .ser file into the .jar file, according to the words I quoted, which makes your question a duplicate. If that isn't what you mean, you have completely failed to make yourself clear. – user207421 Jul 01 '16 at 10:26
  • "I don't want to save INSIDE a .jar because Class.getResourceAsStream(String) as used here only returns an INPUTStream, but I need an OUTputStream to write to a file, which doesn't seem to be possible for .jar resources. So I want to know how I can accomplish what I need, saving an object in a .ser file which can be written to and read [by] the .jar, with the .ser stored outside of the .jar." I may have used the wrong preposition, sorry, in the German language you use them differently... – Dwagner Jul 01 '16 at 10:31
  • So is your question really how to know the location of the .jar file? – user207421 Jul 01 '16 at 10:48
  • In which case see [here](http://stackoverflow.com/questions/4032957/how-to-get-the-real-path-of-java-application-at-runtime/4033090#4033090). – user207421 Jul 01 '16 at 10:57
  • Yeah thanks, already figured it out, I guess I was a bit confused because I dealt with this I/O crap for a few days now and kinda lost it so to say :D. I guess I can continue now... – Dwagner Jul 01 '16 at 12:50

0 Answers0