how to extract jarfile

my goal is to download a jar file from a webserver and extract it to
local disk programmatically using java.
through JarUrlConnection you can get JarFile, however could find any
way to extract the Jarfile to local disk. BTW the jar file could
contain many files and they should be extracted to the local directory
as needed.

Advertisements

On 3 Oct 2005 14:01:50 -0700, "JerryXiao" <>
wrote or quoted :
>my goal is to download a jar file from a webserver and extract it to
>local disk programmatically using java.
>through JarUrlConnection you can get JarFile, however could find any
>way to extract the Jarfile to local disk. BTW the jar file could
>contain many files and they should be extracted to the local directory
>as needed.

If you are using an Applet, it needs to be signed. If you are using
JAWS your installer might contain code like this:

This code unpacks a jar called dicts.jar.

Inside are files called kasxejo.dict nekonato.dict etc.

It opens them with getResourceAsStream and then writes the contents
to local disk with FileOutputStream.

the advantage of using JAWS is your jar is automatically on the
classpath and JAWS assigns you some permanent storage space.

The strange names are in Esperanto.

If you don't like this code, download the Replicator. It contains code
to download jars itself and unpack them itself. Look in the class
com.mindprod.replicator.Fetch

/**
* true if the dictionary data can be found in the jar file, false
in the
* default directory.
*/
boolean inJar;

/**
* Save any changes to this dictionary, and disconnect from it.
*/
public void close ()
{
if ( changed )
{
save();
}
h = null;
} // end close

/**
* Add a definition to the dictionary.
*
* @param word
* The word to be defined in the source language. If word
already
* exists in dictionary, new definition replaces.
* @param definition
* The defininition of the word in the target language. If
null,
* removes existing definition.
*/
public void define ( String word, String definition )
{
if ( !inJar )
{ // would not be able to save back to the jar.
h.put( word, definition );
changed = true;
}
}

/**
* Is it possible to define new words in this dictionary?
*
* @return true if you can add definitions, false otherwise.
*/
public boolean definePossible ()
{
return !inJar;
}

/**
* Looks up a word in a dictionary. It does not do prefix or
suffix
* splitting to help find words. That is the responsibility of
other levels.
*
* @param word
* Word to translate. Lead and trailing blanks removed.
accents
* rendered with trailing x convention, at least for now.
Eventually
* will switch to unicode.
* @return word or phrase for the word translated, possibly with
valid HTML,
* but no excess garbage characters. null if no
translation found.
*/
public String lookup ( String word )
{
return (String)h.get( word );
}

/**
* Open a connection to this dictionary.
*/
public void open ()
{
h = new Properties();
try
{

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!