1

I have a program and I would like it to create a JAR file. Obviously to create a text file you'd just use some FileWriter class, but what arguments would I pass to .write() if it isn't text? For example given the file A.jar, how could the program B.class actually write a copy of A.jar to the computer it's run on?

Basically I'm asking, how do installers work?

rocketsocks
  • 113
  • 3
  • *how do installers work*, hmm, i'm confused between the title and the question inside.. However, if you ask us *how do installers work*, they **extract** the files they want to put into your computer from some sort storage (their own file - like a self extracting zip files, or external file) and do some registration (pre or post installation task which is pretty complex). – Bagus Tesa Oct 15 '17 at 00:25
  • @BagusTesa how do they embed then extract the files? – rocketsocks Oct 15 '17 at 00:38
  • it just a rough idea, i have not fiddled with executables lately.. they remembers the 'offset' or the location where the 'zip' is begin, and then runs the code that does the extraction. well, rather than going full blown playing with binary reading (and perhaps some sorcery, i mean assembly), you could use [7zip sfx module](https://stackoverflow.com/a/30896241/4648586).. – Bagus Tesa Oct 15 '17 at 00:48

1 Answers1

0

A jar file is just a zip file conforming to a specific set of rules.

You can use FileWriter but it is much easier to use the zip file classes. See How to create a zip file in Java for a question about that.

Installers typically unzip a big file producing the various files the application needs (and create shortcuts etc.) You may want to play with launch4j to see how a commonly used installer works.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347