Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6640211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:38:46+00:00 2026-05-25T23:38:46+00:00

I am making a game that needs to be updated. I have two JAR

  • 0

I am making a game that needs to be updated.

I have two JAR files: Update.Jar and Game.Jar
Basically, I want to be able to modify Game.Jar without completely overwriting it.

I want to:

  1. Open the Jar file as a Zip file from within code
  2. Replace/add some resources
  3. Repackage the Jar file.

Is there an easy way or classes that can do this? If not, what would be the cleanest approach to doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:38:46+00:00Added an answer on May 25, 2026 at 11:38 pm

    A Java JAR file is a normal ZIP file. You can therefore open and modify it with code dealing with ZIPs.

    Here’s a snippet which works (courtesy of David):

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    import java.util.zip.ZipOutputStream;
    
    
    public class JarUpdater {
        public static void main(String[] args) {
    
            File[] contents = {new File("F:\\ResourceTest.txt"),
                               new File("F:\\ResourceTest2.bmp")};
    
            File jarFile = new File("F:\\RepackMe.jar");
    
            try {
                updateZipFile(jarFile, contents);
            } catch (IOException e) {
                e.printStackTrace();
            }
    
        }
    
        public static void updateZipFile(File zipFile,
                 File[] files) throws IOException {
                   // get a temp file
            File tempFile = File.createTempFile(zipFile.getName(), null);
                   // delete it, otherwise you cannot rename your existing zip to it.
            tempFile.delete();
    
            boolean renameOk=zipFile.renameTo(tempFile);
            if (!renameOk)
            {
                throw new RuntimeException("could not rename the file "+zipFile.getAbsolutePath()+" to "+tempFile.getAbsolutePath());
            }
            byte[] buf = new byte[1024];
    
            ZipInputStream zin = new ZipInputStream(new FileInputStream(tempFile));
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
    
            ZipEntry entry = zin.getNextEntry();
            while (entry != null) {
                String name = entry.getName();
                boolean notInFiles = true;
                for (File f : files) {
                    if (f.getName().equals(name)) {
                        notInFiles = false;
                        break;
                    }
                }
                if (notInFiles) {
                    // Add ZIP entry to output stream.
                    out.putNextEntry(new ZipEntry(name));
                    // Transfer bytes from the ZIP file to the output file
                    int len;
                    while ((len = zin.read(buf)) > 0) {
                        out.write(buf, 0, len);
                    }
                }
                entry = zin.getNextEntry();
            }
            // Close the streams        
            zin.close();
            // Compress the files
            for (int i = 0; i < files.length; i++) {
                InputStream in = new FileInputStream(files[i]);
                // Add ZIP entry to output stream.
                out.putNextEntry(new ZipEntry(files[i].getName()));
                // Transfer bytes from the file to the ZIP file
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                // Complete the entry
                out.closeEntry();
                in.close();
            }
            // Complete the ZIP file
            out.close();
            tempFile.delete();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a game that needs a crosshair. I have been playing with
I m making a Shooting game, in that I want an array of ImageViews
I am making a game that I want compatible for all older devices to
Trying to implement a timer for my game that I'm making. I have a
I'm making a multiplayer flash game that has a lot of graphics/code. I'm having
I am making a 2D game in javascript/ajax, that will be using data stored
I'm making a website that mail users when a movie or a pc game
I am making a game in JAVA where I want to come up with
I'm making this game where I'm trying to pair people. So I have this
I am trying to do the design of a Bejeweled game. I have basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.